django-rest-framework-filters icon indicating copy to clipboard operation
django-rest-framework-filters copied to clipboard

json complex backend

Open ferrants opened this issue 5 years ago • 14 comments

ferrants avatar Nov 16 '19 04:11 ferrants

Codecov Report

Merging #321 into master will increase coverage by 0.02%. The diff coverage is 100%.

Impacted file tree graph

codecov-io avatar Nov 16 '19 05:11 codecov-io

@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.

ferrants avatar Nov 16 '19 05:11 ferrants

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!

FlipperPA avatar Dec 13 '19 15:12 FlipperPA

@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.

FlipperPA avatar Dec 13 '19 19:12 FlipperPA

bump

rgs258 avatar Mar 26 '20 21:03 rgs258

Considering making another package that can be installed that will include this. This repo isn't very active.

ferrants avatar Mar 26 '20 21:03 ferrants

We'd be happy to help test out and contribute where we can, @ferrants!

FlipperPA avatar Mar 27 '20 13:03 FlipperPA

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.

softzer0 avatar May 07 '20 20:05 softzer0

@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.

ferrants avatar May 07 '20 20:05 ferrants

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.

softzer0 avatar May 07 '20 20:05 softzer0

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"
        }
    }
}

softzer0 avatar May 10 '20 12:05 softzer0

@Soft0 , looks cool. Maybe you should make a library that would do this.

ferrants avatar May 10 '20 18:05 ferrants

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.

softzer0 avatar May 11 '20 08:05 softzer0

Nice work on this! Up 👍

pabrrs avatar Aug 05 '22 15:08 pabrrs