Foreignkey field in admin list_filter, Django 1.0

115 views
Skip to first unread message

caio ariede

unread,
Nov 13, 2008, 8:52:11 AM11/13/08
to django...@googlegroups.com
Hello.

I'm trying to put a field came from a foreignkey in admin list_filter.

My model is something like this:

class UserProfile(models.Model):

user = models.ForeignKey(User, unique=True)

state        = models.CharField(max_length = 2, choices = STATE_CHOICES)
city        = models.CharField(max_length = 200)

in the admin:

class UserProfileAdmin(admin.ModelAdmin):

form = UserProfileAdminForm

def user(obj): return obj.user
def is_staff(obj): return obj.user.is_staff
....

list_display = (user, email, first_name, last_name, is_staff, date_joined)
list_filter = ('is_staff',)


Look that list_display works fine, but I can't put 'is_staff' in list_filter, in Django 0.96 I think the method use 2 underscores, myfk__myfield (user__myfield), but now it doesn't work.

How can I do?

Thanks in advance.

--
Caio Ariede
http://caioariede.com/

caio ariede

unread,
Nov 13, 2008, 1:28:20 PM11/13/08
to django...@googlegroups.com
Nothing about this? :(

I can't put a field came from a foreignkey in a list_filter..

If someone can help..

Ramiro Morales

unread,
Nov 13, 2008, 1:33:42 PM11/13/08
to django...@googlegroups.com
On Thu, Nov 13, 2008 at 4:28 PM, caio ariede <caio....@gmail.com> wrote:
> Nothing about this? :(
>
> I can't put a field came from a foreignkey in a list_filter..
>
> If someone can help..

Have you tried reading the documentation?:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-filter

it doesn't talk about fields of related models being supported at all.

Regards,

--
Ramiro Morales

Reply all
Reply to author
Forward
0 new messages