Friday, January 20, 2017

Pretty printing filters

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.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eba506b0-bdce-4dd7-a809-97051554d26e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment