First, here is an example model:

    Foo
        name

    Bar
        foo = fk(Foo)

    FooBar
        bar = fk(Bar)

Given the above (simplified) model, the following works fine:

    >>> FooBar.objects.filter(bar__foo__name='blah')

However, if I want to use that for a 'list_filter' in the Admin to
filter FooBars by 'name' I get the following Error:

    myproject.foobar: "admin.list_filter" refers to 'bar__foo', which
isn't a field.

For kicks I tried using 'bar.foo' with the same results. I tried
adding '__name' or '.name' to the end (ie.: 'bar__foo_name'), but that
didn't help either.

Can't 'list_filter' filter across mutiple ForeignKeys?

And now I attempt to answer my own question:

It occurs to me that it may be related to the inability to sort such
items in the 'list_display'. For example, in FooBar I also have the
following property defined:

    def _get_bar_foo(self):
      return self.bar.foo
    name = property(_get_bar_foo)

And in the 'list_display' for FooBar:

    list_display = ('name')

Which works great, except that column is not sortable, which is fine
in this case. Even so, I would still like to view only FooBars in
which bar.foo.name = "blah" via 'list_filter'.

-- 
----
Waylan Limberg
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to