I have 2 question models extending the base Question model:
class Question(models.Model):
title = models.CharField(blank=False, max_length=200)
order = models.PositiveIntegerField(default = 0)
is_actuve = models.BooleanField(default = False)
class OptionQuestion(Question):
is_bulletpoint = models.BooleanField(default=False)
has_others = models.BooleanField(default=False)
has_context = models.BooleanField(default=False)
options = ArrayField(models.CharField(max_length=100), verbose_name='گزینهها')
class ItemQuestion(Question):
pass
I originally had the Question
class abstract but i needed a unique id across all questions, and now i am in need of a ListAPIView for both of them.
I have 2 serializers for OptionQuestion
and ItemQuestion
respectively.
I just need to implement a view which would handle a request for a list of questions and handling them with the proper serializer each.
class QuestionListView(ListAPIView):
serializer_class_OptionQuestion = OptionQuestionSerializer
serializer_class_ItemQuestion = ItemQuestionSerializer
def get_queryset_OptionQuestion(self):
#???