Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save akshar-raaj/794633d5a51916e63a3ecc02d0bd2dd6 to your computer and use it in GitHub Desktop.

Select an option

Save akshar-raaj/794633d5a51916e63a3ecc02d0bd2dd6 to your computer and use it in GitHub Desktop.
Question with Choice Serializer dictionary
# polls/models.py
class Question(models.Model):
....
def choices(self):
if not hasattr(self, '_choices'):
self._choices = self.choice_set.all()
return self._choices
# polls/serializers.py
class ChoiceSerializer(serializers.ModelSerializer):
class Meta:
model = Choice
fields = ('id', 'choice_text',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment