Django ModelForm fields - must have more than one?
I have a model which has upwards of 25 fields. I want to create a form to edit only ONE of those fields. Thus I did this:
class My_Model_Form(ModelForm):
class Meta:
model = myModel
开发者_StackOverflowfields = ('myField')
This gave me errors about Unknown field(s) (i, b, l, o, T) specified for My_Model_Form. So, I changed the above to:
class My_Model_Form(ModelForm):
class Meta:
model = myModel
field = ('myField')
(I removed the s from fields). This worked (as in the runserver command runs) however, that form now includes all fields from the model myModel. The only way I can get my desired one-field form is to use the exclude keyword, and list all fields except the one I want. This seems ridiculous.
Am I am going at this all wrong. Is there a better/correct way to do this?
Thanks!
You must have a comma in single-item tuples, otherwise when you iterate over fields it will iterate over each character in the string:
fields = ('myField',)
加载中,请稍侯......
精彩评论