Opened 3 months ago

Closed 3 months ago

Last modified 3 months ago

#35377 closed New feature (wontfix)

Add past and future validators for Date and DateTime fields

Reported by: Jasurbek Yuldoshev Owned by: nobody
Component: Core (Other) Version: 5.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I often see that validating date fields is quite repetitive, for example like this:

def validate_expiration_date(self, value: date) -> date:
        if value <= timezone.now().date():
            raise serializers.ValidationError("Expiration Date must be in future")

        return value

I thought maybe it would be good to have such validation rules out of the box of Django, such as FutureDateValidator(), PastDateValidator().

Change History (2)

comment:1 by Natalia Bidart, 3 months ago

Component: Core (Serialization)Core (Other)
Resolution: wontfix
Status: newclosed

Hello Jasurbek Yuldoshev, thank you for taking the time to create this ticket.

A very similar idea has been presented and rejected a while ago in this email thread.

Given the above:

  • If you are still keen to push this idea forward, the recommended path is to propose and re-discuss the request with the community and gain consensus. To do that, please consider starting a new conversation on the Django Forum, where you'll reach a wider audience and likely get extra feedback. Please reference the past conversation that I linked to provide a complete background for the conversation.
  • I'll close the ticket for now, but if there is a community agreement for this feature request, you are welcome to come back to the ticket and point to the forum topic, so we can then re-open it. For more details, please see the documented guidelines for requesting features.

comment:2 by Natalia Bidart, 3 months ago

Summary: Add new validators for Date fields in serializersAdd past and future validators for Date and DateTime fields
Note: See TracTickets for help on using tickets.
Back to Top