简体   繁体   中英

Adding data in django admin filtering

Hi I have 3 models in my django. Product, Client, and Order.

Class Client(models.Model):
 name = ...
 ....

Class Product(models.Model):
 name = ...
 client = models.ForeignKey(Client)
 .....

Class Order(models.Model):
 qty = ...
 created = ...
 customer_name = ...
 ...
 ...
 client = models.ForeignKey(Client)
 product = models.ForeignKey(Product)

admin.py

    class OrderAdmin(admin.ModelAdmin):
        pass

    admin.site.register(Order, OrderAdmin)

the flow of my project is that, I have so many Clients and each of them have so many products . So when there is an Order , I specify the Clients and the product of the order.

my problem is this, in my Admin page, when I add an Order , select a particular client and when I scroll down the Product field, it will show all the lists of products .

my question is that, is it possible that in admin page,in adding an Order when I scroll the Product , it will show only the Product lists of the client that I have selected? and how to do it?

Yes, its possible and fairly well documented. Here is the official documentation: custom validation . This might also help: stackoverflow link

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