我想在父表单中定义的子类中排除特定字段(data_type
使用 Select 小部件)。我定义了这样的类:
class ParentForm(forms.ModelForm):
data_type = forms.CharField(widget=forms.Select(choices=ANNOTATION_TYPES))
class Meta:
model = Annotation
fields = ('data_value','data_type','active','primary_source')
exclude = ()
class DetailForm(ParentForm):
class Meta(ParentForm.Meta):
exclude = ('data_type','primary_source')
这看起来不错:
print DetailForm.Meta.exclude
('data_type', 'primary_source')
但是,当我打印 HTML 时,我仍然会data_type
在DetailForm
(并且我没有看到其他排除的字段primary_source
)中看到该字段:
print DetailForm(None)
HTML:
<tr><th><label for="id_data_value">Data value:</label></th>..
<tr><th><label for="id_active">Active:</label></th>....
<tr><th><label for="id_data_type">Data type:</label></th><td>
<select name="data_type" id="id_data_type">
<option value="Comment1">Subcellular location</option>
<option value="Comment2">Function</option>
<option value="Comment3">Sequence caution</option>
</select></td></tr>
data_type
看起来定义的方式有问题。有任何想法吗?