From 90eedee3e26f2e6c70d6201f227bca81117e65f0 Mon Sep 17 00:00:00 2001 From: thenav56 Date: Wed, 27 Sep 2023 16:03:32 +0545 Subject: [PATCH] Fix Active QBank resolve issue --- apps/qbank/models.py | 10 +++++----- apps/qbank/queries.py | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/qbank/models.py b/apps/qbank/models.py index 876a3df..33604bc 100644 --- a/apps/qbank/models.py +++ b/apps/qbank/models.py @@ -36,6 +36,9 @@ class Status(models.IntegerChoices): max_length=255, ) + def __str__(self): + return f'{self.pk}: {self.title}' + def activate(self): if self.status != self.Status.SUCCESS: raise ValidationError('QuestionBank status should be success') @@ -44,11 +47,8 @@ def activate(self): self.save(update_fields=('is_active',)) @classmethod - def get_active(cls, queryset: models.QuerySet[typing.Self] | None = None) -> typing.Self | None: - _queryset = queryset - if _queryset is None: - _queryset = cls.objects - return _queryset.filter(is_active=True).order_by('-id').first() + def get_active(cls) -> typing.Self | None: + return cls.objects.filter(is_active=True).order_by('-id').first() class QBChoiceCollection(BaseChoiceCollection): diff --git a/apps/qbank/queries.py b/apps/qbank/queries.py index 7616699..401f714 100644 --- a/apps/qbank/queries.py +++ b/apps/qbank/queries.py @@ -1,6 +1,5 @@ import strawberry import strawberry_django -from asgiref.sync import sync_to_async from strawberry.types import Info @@ -33,6 +32,5 @@ async def question_bank(self, info: Info, pk: strawberry.ID) -> QuestionBankType .afirst() @strawberry_django.field - @sync_to_async def active_question_bank(self) -> QuestionBankType | None: return QuestionBank.get_active()