sehmaschine/django-grappelli — pull request #308 by benjiec (2013-03-22 15:06:02+00:00)
Title: autocomplete lookup not parsing query_string properly

Hi

When using autocomplete lookup, Grappelli honors the query_string set by Django admin. That is, if a model's FK has limit_choices_to={A:B}, Django admin sets the lookup URL to include A=B, and Grappelli turns this into querystring=A=B. However, Grappelli fails to parse A=B correctly.

In Django admin, if A is 'field__isnull' and B is the string 'False', the queryset includes the filter filter__isnull=False. However, in Grappelli, it is field__isnull='False'.

Example:

compound = models.ForeignKey(Compound, limit_choices_to={"related_field__isnull": 'False'})

This causes Grappelli to use the following filter for queryset {"related_field__isnull":"False"}

Fix:

In Django admin, query params are prepared by

from django.contrib.admin.util import prepare_lookup_value

(e.g. django/contrib/admin/filters.py)

Changed related.py view to use that function.