New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear Usage For OrderingFilter
and Calculated Fields
#1244
Comments
Hi @loganknecht. I have to say, thank you for such a wonderful issue report. It starts well, and just gets better. Just so clear. So thank you. First off: it looks like you defined the
So when you say:
I´m expecting the query string parameter to be Then (the bit I´m unsure about in your report) you say it´s a computed field -- what exactly do you mean? i.e. is it a field that appears on the model, or is it a Python property say? Another way of asking (part of) that is does
|
@carltongibson That is quite interesting! I did not expect Using the
|
Hi @loganknecht. Super, looks like you've got it working. 💃 If you're using an annotation then you should be able to filter and order on that with the standard class yes. I'll make a tweak to the docs. Thanks for your input. |
@carltongibson and everyone else, thanks for the amazing library! |
Gratitude
Hello there!
It has been such a pleasure using this library! I'm so thrilled about all the convenience it offers!
Thank you for that!
Goal
My goal right now is I want to have an endpoint that supports search-ability on model parameters, and ordering as well.
Data Model
I have a
School
model that has a calculated field on it calledlearner_enrolled_count
The JSON response looks something like this:
The
learner_enrolled_count
is a calculated field.The Problem
I have read the documentation here:
https://django-filter.readthedocs.io/en/stable/ref/filters.html?highlight=order#orderingfilter
and here:
https://django-filter.readthedocs.io/en/stable/ref/filters.html?highlight=order#adding-custom-filter-choices
So based on that I wrote this filter set here:
This issue is that it doesn't seem to be ordering at all! I have no idea why. It's so strange.
If I drop a debug trace into the
filter
method ofSchoolOrderingFilter
I see thatvalues
isNone
. I'm not sure what that should be.The request I'm making looks like this
{{API_URL}}/api/v1/schools/?offset=5&limit=3&ordering=learner_enrolled_count
And the view that receives this request looks like this:
The Questions
I think it's really unclear for me in the documentation on how to use the filtering feature AND how to use the calculated field ordering.
What am I doing wrong? Am I misunderstanding this functionality? I feel like I'm performing the correct steps for this, but just can't seem to get the
ordering
functionality of this library working!Again, thanks for everything!
The text was updated successfully, but these errors were encountered: