How to limit choice field options based on another choice field in django admin

前端 未结 3 584
盖世英雄少女心
盖世英雄少女心 2020-12-05 00:57

I have the following models:

class Category(models.Model):
    name = models.CharField(max_length=40)

class Item(models.Model):
    name = models.CharField(         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 01:46

    Here is some javascript (JQuery based) to change the item option values when category changes:

    
    

    You need a view to be called on the /items/ URL that supplies a JSON list of the valid items.

    You can hook this into your admin by using model admin media definitions.

提交回复
热议问题