list_filter doesn't appear for model with ForeignKey to auth.models.User

47 views
Skip to first unread message

Carsten Fuchs

unread,
Nov 23, 2010, 2:37:18 PM11/23/10
to Django users
Hi all,

developing my app with Django 1.2.1 and having completed large parts of
the main functionality already, I've now started with familiarizing
myself with user authentication.

I understand that django.contrib.auth.models.User is best extended as
described at
<http://docs.djangoproject.com/en/1.2/topics/auth/#storing-additional-information-about-users>,
but I also want to associate users with some of my regular models. For
example:


> from django.db import models
> from django.contrib.auth.models import User
>
> class Department(models.Model):
> benutzer = models.ManyToManyField(User)
>
> class Team(models.Model):
> head = models.ForeignKey(User)


Unfortunately, with this admin.py


> class DepAdmin(admin.ModelAdmin):
> list_filter = ['benutzer']
>
> admin.site.register(Department, DepAdmin)
>
> class TeamAdmin(admin.ModelAdmin):
> list_filter = ['head']
>
> admin.site.register(Team, TeamAdmin)


none of the two list filters appears in the side bar (other filters that
are similar but whose "target" model is not User work fine).


Thus, my question is, is there something about model "User" that
prevents it from being used with list_filter?
What can I do to have "Departments" and "Teams" filtered by "User"?

Best regards,
Carsten

--
Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
Learn more at http://www.cafu.de

Carsten Fuchs

unread,
Nov 24, 2010, 8:16:35 AM11/24/10
to django...@googlegroups.com
On 11/23/2010 08:37 PM, Carsten Fuchs wrote:
> none of the two list filters appears in the side bar (other filters that
> are similar but whose "target" model is not User work fine).
>
>
> Thus, my question is, is there something about model "User" that
> prevents it from being used with list_filter?
> What can I do to have "Departments" and "Teams" filtered by "User"?

Found the problem:
When there is only one element in a table (one user in User), the
list_filter is not displayed - adding a second user fixed the problem.

Sorry for the noise!

Best regards,
Carsten

Reply all
Reply to author
Forward
0 new messages