Thanks Kasper,
Will try the suggested option.
Meanwhile, do you know how to get the documentation for danjo_filters DateFilter() method, and want to know what all parameters it can accept. Usually we do pass field_name; lookup_expr; label , just curious if we could pass attrs as we pass in forms.Modelform.
I did try checking the document from https://django-filter.readthedocs.io/en/stable/ref/filters.html#datefilter, but there its not mentioned.
Please direct me to the right direction.
Thanks & Regards,
---------------------
Mayank Tripathi
Mo. +1 615 962 2128
---------------------
Mayank Tripathi
Mo. +1 615 962 2128
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
On Fri, Jan 22, 2021 at 2:46 PM Kasper Laudrup <laudrup@stacktrace.dk> wrote:
Hi Maynak,
On 22/01/2021 21.34, Mayank Tripathi wrote:
> Hi All,
>
> I am look for a solution where I can restrict the user to select date
> from current month only instead of selecting any other month or year.
>
> Currently user can select past month as well, have to restrict for
> current month only in date picker.
>
It seems like the HTML date input field has attributes for setting the
min and max value:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#additional_attributes
Setting these attributes to the first and last day of the month for the
widget ought to work:
https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#django.forms.Widget.attrs
Of course, you still need to ensure that the client doesn't send an
invalid/unexpected date.
I haven't tested this, but that's what I'd try to do at least.
Hope that helps.
Kind regards,
Kasper Laudrup
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c56ecb88-6007-107c-e52f-c72f09f05f2a%40stacktrace.dk.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQo0B-6Mk1uxGDCYPP2gMLnk6x%2B507e3vp_LPGaVi7iK1%2B%3D6g%40mail.gmail.com.
No comments:
Post a Comment