Created
May 7, 2019 10:53
-
-
Save akshar-raaj/794633d5a51916e63a3ecc02d0bd2dd6 to your computer and use it in GitHub Desktop.
Question with Choice Serializer dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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