Skip to content

Commit

Permalink
Fix Active QBank resolve issue
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Sep 27, 2023
1 parent 50b1881 commit 90eedee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 5 additions & 5 deletions apps/qbank/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions apps/qbank/queries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import strawberry
import strawberry_django
from asgiref.sync import sync_to_async

from strawberry.types import Info

Expand Down Expand Up @@ -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()

0 comments on commit 90eedee

Please sign in to comment.