REST Calls to Filter Based On Greater Than, Less Than, or Range

92 views
Skip to first unread message

Foobar

unread,
Jan 3, 2019, 5:57:29 PM1/3/19
to Django REST framework
Has anyone successfully used DRF to make API calls using gte, lte, and range? If so, what extension did you use? I've tried django-filters and django-rest-framework-filters but neither work as stated. If someone can share their code that would be much appreciated. Thanks.


Alan Crosswell

unread,
Jan 3, 2019, 6:43:40 PM1/3/19
to django-res...@googlegroups.com

On Thu, Jan 3, 2019 at 5:57 PM Foobar <asadh...@gmail.com> wrote:
Has anyone successfully used DRF to make API calls using gte, lte, and range? If so, what extension did you use? I've tried django-filters and django-rest-framework-filters but neither work as stated. If someone can share their code that would be much appreciated. Thanks.


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alan Crosswell
Associate VP & CTO

Asad Habib

unread,
Jan 3, 2019, 7:42:22 PM1/3/19
to django-res...@googlegroups.com
Alan, thanks. I've gotten it to work now. Is there a way to replace the __ (double underscore) with a single underscore when applying a filter to a field? For example, instead of 

score__range=x,y 

I would like to use 

score_range=x,y

so the Django REST URL is more user friendly. Thanks.

Olivier DUVAL

unread,
Jan 4, 2019, 5:31:37 AM1/4/19
to Django REST framework
I've coded a generic filter for this operations, it's working with date, number, string or list 


For example, URL is like : https://domain.ntld/api/view/?field_operator=threshold||number||lte||30 : filtering threshold field wich is <= 30
you can accumulate filters, ie : https://domain.ntld/api/view/?field_operator=threshold||number||lte||30&field_operator=date_created||date||eq||2019-04-01 : filtering threshlod <= 30 and date_created = 2019-04-01

Jason

unread,
Jan 4, 2019, 8:07:20 AM1/4/19
to Django REST framework
I've tried django-filters and django-rest-framework-filters but neither work as stated

what do you mean by this?   

Alan Crosswell

unread,
Jan 4, 2019, 8:15:53 AM1/4/19
to django-res...@googlegroups.com
Double is what Django uses to indicate a relationship rather than just an underscore that is part of a field_name. You can make a custom field name that is what the client uses as in my example but the actual ORM reference has to use double. 

Alan Crosswell

unread,
Jan 4, 2019, 9:47:12 AM1/4/19
to django-res...@googlegroups.com
Specific example here where the DRF client uses "name" but the actual ORM relationship path is "course_terms__instructor__person__name".

Gonzalo Amadio

unread,
Jan 7, 2019, 5:18:52 AM1/7/19
to Django REST framework
Can you give code why they don't work?
Error messages, debug code?

El sáb., 5 ene. 2019 0:07, Jason <jjohn...@gmail.com> escribió:
I've tried django-filters and django-rest-framework-filters but neither work as stated

what do you mean by this?   

--
Reply all
Reply to author
Forward
0 new messages