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?
实际上,您可以在ORM查询中向后使用外键关系。
User.objects.filter(foo__isnull=False)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.