Django Search Between 2 Dates

44 views
Skip to first unread message

Eugene TUYIZERE

unread,
Feb 3, 2021, 6:12:34 AM2/3/21
to django...@googlegroups.com
Dear Team,

I need help. I have a list of Items in a table. And I want to filter some data between dates (start and end date). Please help me to do a search between the two date. I am using Data table but I can use the other way if possible for this purpose.

Regards, 

--
TUYIZERE Eugene

Msc Degree in Mathematical Science

African Institute for Mathematical Sciences (AIMS Cameroon)
Crystal Garden-Lime, Cameroon


Bsc in Computer Science

UR-Nyagatare Campus

Email: eugene....@aims-cameroon.org
           eugenet...@gmail.com

Tel: (+250) 7 88 26 33 38, (+250) 7 22 26 33 38

Thiago Luiz Parolin

unread,
Feb 3, 2021, 8:16:49 AM2/3/21
to django...@googlegroups.com
Hi...
Normally i use field__lte and field__gte 

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABxpZHuPozCVEUFjWFYxipwTyGrY9Syyw-Et%2B_NAqXn6GevNow%40mail.gmail.com.

Eugene TUYIZERE

unread,
Feb 3, 2021, 8:24:40 AM2/3/21
to django...@googlegroups.com
Dear Thiago,

Can I have some documentations or sample codes please?

Steven Mapes

unread,
Feb 3, 2021, 8:40:22 AM2/3/21
to Django users
Are you looking at client-side filtering within datatables or server side filtering? Thiago's suggestion related to using filters when you fetch the queryset (https://docs.djangoproject.com/en/3.1/topics/db/queries/#retrieving-specific-objects-with-filters)

Thiago Luiz Parolin

unread,
Feb 3, 2021, 1:10:34 PM2/3/21
to django...@googlegroups.com
I will try to explain, although I am not a good teacher.

Suppose you have an 'Example' model that has a 'data' field with 'auto_now_add = True'
And a function 'yesterday()' that returns yesterday, and 'past()' that returns 'yesterday() minus some days'.
if you want to filter items between yesterday() and past(), you could use something like:

Example.objects.filter(data__gte=past(),data__lte=yesterday())
 or using .exclude too
If you need more info, you can get better in django docs:
https://docs.djangoproject.com/en/3.1/ref/models/querysets/

I hope I helped a little despite my bad English.







--
Thiago Luiz Parolin

Thiago Luiz Parolin

unread,
Feb 3, 2021, 1:12:36 PM2/3/21
to django...@googlegroups.com
If you want clien-side, then you need to make some script-fu using jquery or anything like that.



--
Thiago Luiz Parolin

Siarhei Siarhei

unread,
Feb 4, 2021, 10:12:26 AM2/4/21
to Django users
https://otus.ru/nest/post/286/

среда, 3 февраля 2021 г. в 21:12:36 UTC+3, thiago.parolin:
Reply all
Reply to author
Forward
0 new messages