我有以下表格,我想用我准备的自动完成小部件覆盖 manytomanyfield。
class AutoCompleteForeignKeyWidget(forms.TextInput):
input_type = 'text'
class FooForm(forms.ModelForm):
regions = forms.CharField(widget=AutoCompleteForeignKeyWidget(attrs={
'class': 'regions', 'placeholder': 'Type Region',
'autocomplete': 'off'
}), required=True)
class Meta:
model = Hotel
exclude = ('regions')
但这是不成功的。我得到一个完整性错误DETAIL: Key (region_id)=(0) is not present in table "destinations_region".
有没有办法覆盖 manytomanyfield