diff options
author | 2019-04-25 20:30:37 +0200 | |
---|---|---|
committer | 2019-04-25 20:30:37 +0200 | |
commit | 4a67a0646761802e5b6f1996f74ea7f7a9a1f2d9 (patch) | |
tree | a3a60c376c700ca05a2c42ad5237a4f6d99035a5 | |
parent | Reworking nomination viewset and model (diff) |
Adding validate to Nomination serializer
-rw-r--r-- | pydis_site/apps/api/serializers.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py index 54f26466..6fb9d826 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -173,12 +173,22 @@ class UserSerializer(BulkSerializerMixin, ModelSerializer): class NominationSerializer(ModelSerializer): - author = PrimaryKeyRelatedField(queryset=User.objects.all()) + actor = PrimaryKeyRelatedField(queryset=User.objects.all()) user = PrimaryKeyRelatedField(queryset=User.objects.all()) class Meta: model = Nomination fields = ( - 'id', 'active', 'author', 'reason', 'user', + 'id', 'active', 'actor', 'reason', 'user', 'inserted_at', 'unnominate_reason', 'unwatched_at') depth = 1 + + def validate(self, attrs): + active = attrs.get("active") + + unnominate_reason = attrs.get("unnominate_reason") + if active and unnominate_reason: + raise ValidationError( + {'unnominate_reason': "An active nomination can't have an unnominate reason"} + ) + return attrs |