简体   繁体   中英

Django-admin dynamically filter ForeignKey field

I have a model:

class Foo(models.Model):
    pass
class Bar(models.Model):
    foo = Models.ForeignKey(Foo)
class Last(models.Model):
    bar = Models.ForeignKey(Bar)

When I want to create a new instance of Last , bar field in djando-admin contains all instances of Bar. How to filter it by relationship with Foo?

Thanks

Admin类中的raw_id_fields = ('bar',)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM