Django ModelForm to have a hidden input

前端 未结 4 810
孤城傲影
孤城傲影 2020-12-01 02:03

So I have my TagStatus model. I\'m trying to make a ModelForm for it. However, my form requires that the hidden input be populated with the {{ tag.name }}. I\'ve been lookin

4条回答
  •  北海茫月
    2020-12-01 02:36

    I was looking for a way to HIDE ALL INPUTS :

    class TagStatusForm(forms.ModelForm):
        class Meta:
            model = TagStatus
    
        def __init__(self, *args, **kwargs):
            super(TagStatusForm, self).__init__(*args, **kwargs)
            for field in self.fields:
                self.fields[field].widget = forms.HiddenInput()
    

提交回复
热议问题