I suppose Min / MaxValueValidator cannot be reused here because they expect a fixed bound, while past / future depends on the current date?
The implementation Mariano provided looks simple enough to reproduce and adapt to each project’s requirements (even though I’d prefer duck typing to type checks). Note that it assumes that USE_TZ = False while Django sets USE_TZ = True by default. -- Aymeric. > On 31 Aug 2016, at 03:04, Tim Graham <[email protected]> wrote: > > Thanks for the proposal. MaxValueValidator and MaxValueValidator are included > because they're needed for IntegerField validation. I don't think the > proposed validators meet the criteria of "needed in 80% of Django projects" > or "can't easily be implemented as a third-party app". > > On Tuesday, August 30, 2016 at 4:20:36 PM UTC-4, Mariano Baragiola wrote: > Hello django-developers@, > > On more than one project, I find myself implementing the same feature over > and over again. It's not a rare case scenario, for instance: it's common > that invoices have a date that belongs to the past or the present time, but > not the future. > > Seeing that we have django.core.validators.MinValueValidator and > django.core.validators.MaxValueValidator, I propose the following: > > * django.core.validators.DateIsPresent > * django.core.validators.DateIsPresentOrPast > * django.core.validators.DateIsPresentOrFuture > * django.core.validators.DateIsFuture > > This way, one may easily use them at models.py just like MinValueValidator > and MaxValueValidator. > > The code would be really simple, I have them -differently- implemented at: > https://github.com/heimdalerp/heimdalerp/blob/master/common/validators.py > <https://github.com/heimdalerp/heimdalerp/blob/master/common/validators.py> > > Please, let me know if there's already an easier way to do this with > current Django, or if this belongs to a custom app instead. > > If it is ok to add this feature to Django, I can gladly take care of it. > > Thanks in advance. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/django-developers > <https://groups.google.com/group/django-developers>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/62bd473f-19bb-4140-b04f-ba733e8b78e5%40googlegroups.com > > <https://groups.google.com/d/msgid/django-developers/62bd473f-19bb-4140-b04f-ba733e8b78e5%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8421D044-5BD2-4375-A3B6-CA0E0077638F%40polytechnique.org. For more options, visit https://groups.google.com/d/optout.
