Andrea
Andrea

Reputation: 20493

Django admin - Create a complex filter on User model

I have a field Foo with a ForeignKey that points to User. I need to create filter in the admin that only displays User that have at least one Foo. This would be easy with the development version of Django, but I am stuck with the 1.3.

I have seen here how to add a custom filter using the undocumented FilterSpec class. My problem is that it requires to modify the User model. I could inherit from User, but I already ave a setup where additional data is put into a Profile model wiith a one-to.one link to User.

Is there a less intrusive way to add a custom filter to the User model?

Upvotes: 1

Views: 477

Answers (1)

pyrospade
pyrospade

Reputation: 8078

You can actually use the foreign key relation backwards in an ORM query.

User.objects.filter(foo__isnull=False)

Upvotes: 1

Related Questions