How to use custom form fields for model fields in the Django admin?

前端 未结 1 1864
走了就别回头了
走了就别回头了 2021-02-20 13:20

I want to have the Django admin use a custom form field for the input of some fields.

Until now I made a custom model field that has the form field bound to it which wor

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-20 13:32

    class MyModelForm(forms.ModelForm):
        my_field = MyCustomFormField()
    
        class Meta:
            model = MyModel
    
    class MyModelAdmin(admin.ModelAdmin):
        form = MyModelForm
    

    0 讨论(0)
提交回复
热议问题