Django admin choice field

前端 未结 7 1666
日久生厌
日久生厌 2020-12-18 22:48

I have a model that has a CharField and in the admin I want to add choices to the widget. The reason for this is I\'m using a proxy model and there are a bunch of models tha

7条回答
  •  别那么骄傲
    2020-12-18 22:51

    in Gerard's answer, if you keep :

    def __init__(self, stuff_choices=(), *args, **kwargs):
    

    then when you will try to add new model from admin, you will always get 'This field is required.' for all required fields.

    you should remove stuff_choices=() from initialization:

    def __init__(self,*args, **kwargs):
    

提交回复
热议问题