SOITA/questions/managers.py

30 lines
726 B
Python
Raw Normal View History

2021-12-12 11:35:35 +01:00
from django.db.models import Manager
from django.apps import apps
from django.conf import settings
from categories.models import Category
class QuestionManager(Manager):
def create(
self, *,
answers=[],
2021-12-13 23:22:11 +01:00
name=None,
2021-12-12 11:35:35 +01:00
test=None,
2021-12-12 23:34:54 +01:00
description=None,
2021-12-12 11:35:35 +01:00
**kwargs
):
Answer = apps.get_model("answers", "Answer")
instance = super().create(
2021-12-13 23:22:11 +01:00
name=name,
2021-12-12 11:35:35 +01:00
test=test,
2021-12-13 23:22:11 +01:00
description=name,
2021-12-12 11:35:35 +01:00
)
for answer in answers:
Answer.objects.create(
question=instance,
description=answer["description"],
is_correct=answer["is_correct"]
)
return instance