django-rest-framework-filters
django-rest-framework-filters copied to clipboard
json complex backend
@philipn , we found the existing Complex Backend to be too annoying to integrate with because of the double encodings and the order of and and or wasn't explicit enough. We are using this in our app instead and thought we could contribute it back.
This looks fantastic, @ferrants - thank you for the contribution.
@rpkilby - what do you think about this direction? I'm hesitant to use it until it receives your blessing going forward. Thanks!
@ferrants A total nitpick, but one that was pointing out to me on one of my projects recently, so I figured I'd pay it forward! This really looks excellent, I'm hoping for a merge.
bump
Considering making another package that can be installed that will include this. This repo isn't very active.
We'd be happy to help test out and contribute where we can, @ferrants!
This project is so inactive that even the pip package has older version in it. When this will be merged into the main branch and repository for pip updated, @rpkilby, @philipn, anyone? I need it for my project to properly include it into requirements file.
@Soft0 , you can probably copy the code for the ComplexJSONFilterBackend into your project and it should work. I doubt this will get merged, this project isn't active.
What a shame. Maybe you should continue on this project from your fork and create a new pip package from it?
My workaround is that I have just specified your repository and branch (git+https://github.com/ferrants/django-rest-framework-filters.git@json-filter) in requirements file.
Hey @ferrants, it would be really nice if annotation exists along this filter. It would be then the complete solution. For example, this:
User.objects.annotate(
foo=Sum(Case(When(
Q(history__action__name='argle') | Q(history__action__name='bargle'),
history__since__lte=now,
history__until__gte=now,
then=1
), output_field=IntegerField()))
)
To be translated from this JSON query:
{
"foo": {
"type": "Sum",
"value": {
"type": "Case",
"When": [
{
"and": [
{
"or": [
{
"history__action__name": "argle"
},
{
"history__action__name": "bargle"
}
]
},
{
"history__since__lte": "2020-05-10T09:50:54.018Z",
"history__until__gte": "2020-05-10T09:50:54.018Z"
}
],
"then": 1
}
],
"output_field": "IntegerField"
}
}
}
@Soft0 , looks cool. Maybe you should make a library that would do this.
Unfortunately I don't have much experience to work on it, that's why I proposed to you. Maybe if it's much needed in the future I would need to knock off some sloppy implementation. Until then I will stick to this and make annotation queries directly in the code of the view.
Nice work on this! Up 👍