-
Notifications
You must be signed in to change notification settings - Fork 771
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
Add filter to support 1,2,3 syntax #259
Conversation
Thanks for the shout-out 😄 |
Credit where it's due. Yours allowed simple coercion, that I hadn't considered since I'd only used it with strings. |
Hi @carltongibson, is this the right direction? Sorry, if you were planning on looking at this already. |
Hi @zoidbergwill. Thanks for the PR. My initial thought is that this needs to be done at the widget level rather than the filter. Look at the SelectMultiple widget — it is responsible for calling If we're going to add support for the I know most probably want this for DRF related work, rather than building HTML forms, but some consideration should probably go into the Also we need to document when/where/how devs would use the new widget. |
Thanks I'll take a look at the I only really have experience with the DRF-related uses for the filters, but I'll take a look at the HTML forms stuff and try my best to match the behaviour. I've written some basic documentation for the filter that I haven't pushed yet, so I'll write some once the widget work is done too. |
First pass I'd guess sublclass
|
Thanks for all the help.
So I made a widget that matches the filter behaviour, so should I get rid of the filter? Will the widget be used when I send GET parameters to the filter in DRF? Sorry, I tried to test the filter side with widgets, without any success. I have working tests for the widget though. |
@carltongibson Does this look more in the right direction? |
Hey @zoidbergwill — Yes. That looks more or less what I had in mind. I think people are going to want an example of how to specify the widget using the |
Hi @carltongibson, is there a way to use the widget with a REST endpoint? I've looked through the code and docs. I feel like I'm missing something. Am I doing the logic at the wrong point in the widget? |
Hey @zoidbergwill. The flow goes You should be able to do this at declaration but if not override init, pull the filter and set it by hand. (If you're getting stuck I'll need to see your code — what are you trying that's not working?) |
Take another look here: https://django-filter.readthedocs.org/en/latest/usage.html#the-filter — the (Let me know how you get on: both for the docs here and in general.) |
So I was having some issues with testing this against an existing project, because of the Django I've added a simple I can't see an easier solution with a better filter function to override or anything. |
Sorry @carltongibson, I missed your first of the two comments there. |
I'll push the field and filter stuff I've added, and I can add tests if it's gonna stay or I can rebase it out. |
Ok, Thanks for the effort let me have a look at what you've got here and we'll see how to go forward. |
Django forms.CharField's to_python function. It calls __unicode__ when sent a list. I also added a CSVFilter, that uses the CSVField.
I tried writing tests, but there's nothing really worth testing that I added. |
Hi @zoidbergwill,
This confuses me. We're talking about adding a new widget for use with a SelectField on a MultipleChoiceFilter right. Where does the Can you put your FilterSet declaration either here, or in a test case (that you'd like to pass) or in Gist and I'll take a look? Thanks |
Sorry, I haven't had the time to work on this. I'll have time in the next few weeks. |
Will the proposed code allow a developer to support syntax like this?
or only something like:
What about support for __range lookup, e.g.;
|
This should really be added to make django-filter practical to use. In Ruby this feature has landed long ago in the default filtering gem. |
Gonna give this another try. |
@zoidbergwill — OK. Cool. No stress. :-) Rather than a filter, look at just creating a widget. |
I'm going to close this pending the new version. |
Based on discussion from #137
Using some of @kmwenja's work from his comment, and some from the original gist I had.
I considered using similar terms to Django for cleaning/validating the values, but I left it with the function names used in the comment where the cleaning was suggested.