class Question(models.Model):
answer_choices = models.ManyToManyField(Answers)
class Meta:
abstract = True
class HTMLQuestion(Question):
question = models.fields.TextField()
class TextQuestion(Question):
question = models.fields.TextField()
class Quiz(models.Model):
questions = models.ManyToManyField(Question)
The last line doesn't work. I can't run python manage.py makemigrations
without the error "Field defines a relation with model 'Question', which is either not installed, or is abstract."
Is there a way to have a list of Question subclassed instances without having it be of type "Question"? I want to have both types HTMLQuestion and TextQuestions to be in the Quiz.
The answer I ended up with was to forget working with inheritance in Django and instead to put the type in the Question and then created functions of how to deal with that type in the Question model itself.
class Question(models.Model):
answer_choices = models.ManyToManyField(Answers)
question_type = models.fields.TextField() # "htmlquestion", "textquestion"
def how_to_deal_with_type(question_type):
# code here
class Quiz(models.Model):
questions = models.ManyToManyField(Question)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With