How can I disable a model field in a django form

前端 未结 5 1985
野性不改
野性不改 2020-12-13 10:37

I have a model like this:

class MyModel(models.Model):
    REGULAR = 1
    PREMIUM = 2
    STATUS_CHOICES = ((REGULAR, \"regular\"), (PREMIUM, \"premium\"))
         


        
5条回答
  •  有刺的猬
    2020-12-13 11:20

    Have you tried using the exclude function?

    something like this

    class PartialAuthorForm(ModelForm):
    class Meta:
        model = Author
        fields = ('name', 'title')
    
    class PartialAuthorForm(ModelForm):
    class Meta:
        model = Author
        exclude = ('birth_date',)
    

    Reference Here

提交回复
热议问题