Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin URL query string "OR". Is it possible?

I love being able to write quick and dirty query strings right into the URL of the Django admin. Like: /admin/myapp/mymodel/?pub_date__year=2011

AND statements are just as easy: /admin/myapp/mymodel/?pub_date__year=2011&author=Jim

I'm wondering if it's possible to issue an 'OR' statement via the URL. Anyone heard of such functionality?

like image 897
Dustin Farris Avatar asked Nov 22 '11 17:11

Dustin Farris


People also ask

Does URL include query string?

A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters.

How do I find my Django admin URL?

Open a browser on the Django admin site http://127.0.0.1:8000/admin/.

What is query string in Django?

Django processes the query string automatically and makes its parameter/value pairs available to the view. No configuration required. The URL pattern refers to the base URL only, the query string is implicit. For normal Django style, however, you should put the id/slug in the base URL and not in the query string!

What is the query string in a URL and what does it do?

On the internet, a Query string is the part of a link (otherwise known as a hyperlink or a uniform resource locator, URL for short) which assigns values to specified attributes (known as keys or parameters). Typical link containing a query string is as follows: http://example.com/over/there? name=ferret.


2 Answers

Django < 1.4 doesn't support OR queries. Sometimes it is possible to translate OR queries to __in - queries which are supported (they are equivalent to OR queries but only for single field values).

You can also upgrade to django development version: it has more versatile list_filter implementation (see https://docs.djangoproject.com/en/dev//ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter ) which can be used for providing advanced admin filters (including OR-queries).

like image 73
Mikhail Korobov Avatar answered Sep 30 '22 17:09

Mikhail Korobov


The & is not a logical AND, even though it seems to be acting that way in your case. I'm pretty certain there is no way to create a logical OR in the GET query string.

like image 28
Furbeenator Avatar answered Sep 30 '22 16:09

Furbeenator