Pretty printing filters

13 views
Skip to first unread message

Bernd Wechner

unread,
Jan 20, 2017, 7:17:39 AM1/20/17
to Django users
I've implement a list view using the rather awesome Django URL filter package:


Basically it makes it easy to filter  a list view just by putting Django filter terms in the URL (as GET params)

Now I find myself wanting to report the filter in use on the view. I can sit down and write a pretty printer for a django filter but can't help wonder if and suspect that it's been done before and I'm just not seeing it.

I mean to cut an example  from the Django docs, this sort of filter:

Blog.objects.filter(entry__headline__contains='Lennon', entry__authors__name='Lennon')

would be specified on a URL as:

mysite.com/listview?entry__headline__contains=Lennon&entry__authors__name=Lennon

Now it would be nice to print at the top of the list a summary of the filter like:

entry->headline contains 'Lennon'
        and
entry->authors->name is 'Lennon'

The thing is there's a fair translation required from the neat filter syntax to a humanized version.

Has this been done before? Can I find a tool for it? Or will I look at writing one? Hard to imagine no-ones wanted this before.

Regards,

Bernd.
Reply all
Reply to author
Forward
0 new messages