Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#423 closed defect (fixed)

Admin filters broken with [549]

Reported by: jkocherhans@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I changed my models over to the new syntax and svn up'd django this morning. Everything seems to work fine except for filters in the admin interface. I have a ForeignKey realtion called 'site'... the admin interface generates a url like:

Which results in the traceback below. If I manually type in the url:

It works as expected. I'm not sure if this is a problem with the admin interface, or the db api. According to the new db api docs, it looks like a problem with the admin interface though.

Traceback (most recent call last):

  File "/usr/local/lib/python2.4/site-packages/django/core/handlers/", line 64, in get_response
    response = callback(request, **param_dict)

  File "/usr/local/lib/python2.4/site-packages/django/views/admin/", line 177, in change_list
    result_count = p.hits

  File "/usr/local/lib/python2.4/site-packages/django/core/", line 67, in _get_hits
    self._hits = getattr(self.module, self.count_method)(**order_args)

  File "/usr/local/lib/python2.4/site-packages/django/utils/", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/usr/local/lib/python2.4/site-packages/django/core/meta/", line 1127, in function_get_count
    _, sql, params = function_get_sql_clause(opts, **kwargs)

  File "/usr/local/lib/python2.4/site-packages/django/core/meta/", line 1299, in function_get_sql_clause
    tables2, join_where2, where2, params2, _ = _parse_lookup(kwargs.items(), opts)

  File "/usr/local/lib/python2.4/site-packages/django/core/meta/", line 1228, in _parse_lookup

  File "/usr/local/lib/python2.4/site-packages/django/core/meta/", line 1178, in _throw_bad_kwarg_error
    raise TypeError, "got unexpected keyword argument '%s'" % kwarg

TypeError: got unexpected keyword argument 'site__exact'

Change History (3)

comment:1 Changed 13 years ago by jkocherhans@…

I haven't tested the code below, but it should show my point.

class Foo(meta.Model):
    name = meta.CharField(maxlength=255)

class Bar(meta.Model):
    name = meta.CharField(maxlength=255)
    foo = ForeignKey(Foo)
    class META:
        admin = meta.Admin(

The link for each filter item is like:

etc, but the page for this links don't work. (See the taceback above.) These work however:

Despite reading the docs, I'm not sure what the expected behavior is. If the second set set of links should work, here's a patch to fix the admin interface. If the first set of links should work, then I can't figure out how to fix it at first glance. It seems to me, that with the new model syntax, both should work. Hopefully this is a little clearer than my initial report.

Index: django/views/admin/
--- django/views/admin/  (revision 558)
+++ django/views/admin/  (working copy)
@@ -199,7 +199,7 @@
                     lookup_kwarg = '%s__id__exact' %
                     lookup_title =
-                    lookup_kwarg = '%s__exact' %
+                    lookup_kwarg = '%s__id__exact' %
                     lookup_title = f.verbose_name
                 lookup_val = request.GET.get(lookup_kwarg, None)
                 lookup_choices =

comment:2 Changed 13 years ago by Adrian Holovaty

Status: newassigned

comment:3 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: assignedclosed

Fixed in [569].

Note: See TracTickets for help on using tickets.
Back to Top