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
| Question.objects.annotate(num_votes=Sum('choice__votes')) |
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
| Question.objects.filter(question_text='Is the color of sky blue').annotate(choice_count=Count('choice')) |
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
| Question.objects.annotate(choice_count=Count('choice')) |
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
| Choice.objects.count() |
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
| Question.objects.count() |
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
| class Question(models.Model): | |
| question_text = models.CharField(max_length=200) | |
| def __str__(self): | |
| return self.question_text | |
| class Choice(models.Model): | |
| question = models.ForeignKey(Question, on_delete=models.CASCADE) | |
| choice_text = models.CharField(max_length=200) |
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
| class UserSerializer(serializers.ModelSerializer): | |
| def validate_password(self, value): | |
| if value.isalnum(): | |
| raise serializers.ValidationError('password must have atleast one special character.') | |
| return value | |
| def validate(self, data): | |
| if data['first_name'] == data['last_name']: | |
| raise serializers.ValidationError("first_name and last_name shouldn't be same.") |
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
| def create(self, validated_data): | |
| return User.objects.create_superuser(**validated_data) |
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
| def to_internal_value(self, value): | |
| value['date_joined'] = parser.parse(value['date_joined']) | |
| return super().to_internal_value(value) |
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
| class UserSerializer(serializers.ModelSerializer): | |
| def validate_password(self, value): | |
| if value.isalnum(): | |
| raise serializers.ValidationError('password must have atleast one special character.') | |
| return value | |
| def validate(self, data): | |
| if data['first_name'] == data['last_name']: | |
| raise serializers.ValidationError("first_name and last_name shouldn't be same.") |