notes from discord chat
Add backend validation so group admin is not able to create deliberation / delegation / election in the wrong date order via the API.
Object-level validation
To do any other validation that requires access to multiple fields, add a method called .validate() to your Serializer subclass. This method takes a single argument, which is a dictionary of field values. It should raise a serializers.ValidationError if necessary, or just return the validated values. For example:
from rest_framework import serializers
class EventSerializer(serializers.Serializer):
description = serializers.CharField(max_length=100)
start = serializers.DateTimeField()
finish = serializers.DateTimeField()
def validate(self, data):
"""
Check that start is before finish.
"""
if data['start'] > data['finish']:
raise serializers.ValidationError("finish must occur after start")
return data
Originally posted by @whatSocks in https://github.com/RadicalxChange/rxc-voice/issues/47#issuecomment-879378186
Solution from DRF docs