how to modify choices on admin pages - django

后端 未结 4 769
猫巷女王i
猫巷女王i 2020-12-15 11:27

I have a model that has a field named \"state\":

class Foo(models.Model):
    ...
    state = models.IntegerField(choices = STATES)
    ...

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 12:05

    This seems like a job for some javascript. You want the list of items in a select box to change depending on the value of something else, which is presumably a checkbox or radio button. The only way to make that happen dynamically - without getting the user to save the form and reload the page - would be with javascript.

    You can load custom javascript in a model's admin page by using the ModelAdmin's Media class, documented here.

提交回复
热议问题