Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce correct start / end date orders for event stages #84

Open
alexrandaccio opened this issue Dec 8, 2021 · 0 comments
Open

Enforce correct start / end date orders for event stages #84

alexrandaccio opened this issue Dec 8, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@alexrandaccio
Copy link
Member

alexrandaccio commented Dec 8, 2021

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.

Originally posted by @whatSocks in #47 (comment)

Solution from DRF docs

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
@alexrandaccio alexrandaccio added bug Something isn't working Good first issue Good for newcomers labels Dec 8, 2021
@alexrandaccio alexrandaccio removed the Good first issue Good for newcomers label Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant