-
Notifications
You must be signed in to change notification settings - Fork 77
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
Cannot filter on jsonfields (django) #21
Comments
@ohenrik sorry for the late response unfortunately currently thats not possible since different filtersets cant be mixed and matched. this is a great idea though. would be nice to be able to do something like: class DataFiltersFilterSet(PlainModelFilterSet):
class Meta:
model = {
'my': 'json'
}
class MyModelFilterSet(ModelFilterSet):
data_filters = DataFiltersFilterSet()
class Meta:
model = MyModel
fields = ['id', ...] Issue now is to filter queryset, only a single backend is used. since Django model backend would be unable to filter plain objects, it would not be able to filter on json object data. And vice-versa for plain backend would not be able to filter Django models. Can you explain a bit more about your usage example so maybe there would be temporary solution for you? |
Hi, revisiting this issue since we are running into the problem as well. Currently if a jsonfield contains a dictionary we are unable to filter for a value for a key in that dictionary. For example:
And we have the following data for the options:
We can not write our query like the following:
but in Django we can write it as follows
I guess django_url_filter thinks "options" is a related model. Is therea way to get this to work with the current implementation? Thanks |
currently json fields are not supported. sorry. |
Hi @miki725 , I would like to contribute and take up this task to add json field support. Are there guidelines on how do I become a contributor? |
no specific guidelines. the complexity with json fields is that it will require some structure changes to the library which im not sure how to proceed with yet. I have some ideas brewing in my head. when will have some free time (or if will actually require them in personal/work project 😄 ) will experiment what works better. there are couple of aspects which I dont particularly enjoy at the moment like lookups are not restricted per field type. fixing that pattern with additional abstraction layer below backend can potentially help with json fields too. fee free to try get something running for json fields and send pr although no guarantees it will be merged but could be great to start a discussion on how to approach the solution. |
I have made a PR #82 that adds support for filtering against JSONField()'s |
I'm trying to filter on a jsonfield in django named
data_filters
. However it seems like this is not working when I'm not specifying any filters. And when i try to spesify filters it crashes because the same fields are not present everywhere.Is there a way to not validate filters? So that i can just pass along any filter value? for example
?data_filters__region__id=01,02
Edit: Can i use the plain filter to acchieve this?
Also it seems like the pip install version of this gem (0.2.0) does not include the plain version of the filter, it seems like i have to request the master branch to get this.
The text was updated successfully, but these errors were encountered: