-
Notifications
You must be signed in to change notification settings - Fork 130
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
json complex backend #321
base: master
Are you sure you want to change the base?
json complex backend #321
Conversation
@philipn , we found the existing Complex Backend to be too annoying to integrate with because of the double encodings and the order of |
tests/testapp/views.py
Outdated
@@ -52,6 +52,19 @@ class pagination_class(pagination.PageNumberPagination): | |||
page_size_query_param = 'page_size' | |||
|
|||
|
|||
class ComplexJsonFilterFieldsUserViewSet(FilterFieldsUserViewSet): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP-8 nitpick: ComplexJSONFilterFieldsUserViewSet
JSON (and all acronyms) should be capitalized: Note: When using acronyms in CapWords, capitalize all the letters of the acronym. Thus HTTPServerError is better than HttpServerError.
rest_framework_filters/backends.py
Outdated
@@ -94,3 +98,60 @@ def get_filtered_querysets(self, querystrings, request, queryset, view): | |||
if errors: | |||
raise ValidationError(errors) | |||
return querysets | |||
|
|||
|
|||
class ComplexJsonFilterBackend(RestFrameworkFilterBackend): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComplexJsonFilterBackend -> ComplexJSONFilterBackend
@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! |
@Soft0 , you can probably copy the code for the |
What a shame. Maybe you should continue on this project from your fork and create a new pip package from it? |
Hey @ferrants, it would be really nice if annotation exists along this filter. It would be then the complete solution. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix the small merge conflict. the works looks great
Nice work on this! |
No description provided.