Django 如何排除使用选择小部件的父字段?

Django 如何排除使用选择小部件的父字段?,django,django-forms,Django,Django Forms,我想排除父窗体中定义的子类中的特定字段(data\u type,它使用Select小部件)。我对类的定义如下: class ParentForm(forms.ModelForm): data_type = forms.CharField(widget=forms.Select(choices=ANNOTATION_TYPES)) class Meta: model = Annotation fields = ('data_value','data

我想排除父窗体中定义的子类中的特定字段(
data\u 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时,我仍然会在
详细表单中看到字段
数据类型
(并且我没有看到其他排除的字段
主要源代码
):

HTML:

数据值:。。
活动:。。。。
数据类型:
亚细胞定位
作用
顺序警告

看来
数据类型的定义方式有问题。有什么想法吗?

因为
数据类型
不是一个模型字段,所以这不起作用。您需要删除
\uuuu init\uuuu
中的字段:

class DetailForm(ParentForm):
    def __init__(self, *args, **kwargs):
        super(DetailForm, self).__init__(*args, **kwargs)
        del self.fields['data_type']
<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>
class DetailForm(ParentForm):
    def __init__(self, *args, **kwargs):
        super(DetailForm, self).__init__(*args, **kwargs)
        del self.fields['data_type']