UpdateView

时间:2017-12-01 06:31:39

标签: django

我可以在UpdateView中使用替代表单吗?我的意思是如果它已经创建了。我尝试使用' form_class'但它有例外:"   init()得到了一个意外的关键字参数'实例'"

Form: class ProfileForm(forms.Form):

name = forms.RegexField(regex=r'^\D+$', error_messages={'invalid':'Error Name'}, label='', widget=forms.TextInput({"placeholder": 'Имя'}),)
surname = forms.RegexField(regex=r'^\D+$', error_messages={'invalid':'Surname Name'}, label='', widget=forms.TextInput({"placeholder": 'Фамилия'}),)
patronymic = forms.RegexField(regex=r'^\D+$', error_messages={'invalid':'Patrh Name'}, label='', widget=forms.TextInput({"placeholder": 'Отчество'}),)
address = forms.RegexField(regex=r'^\D+$', error_messages={'invalid': 'Address incorrect'}, label='', widget=forms.TextInput({"placeholder": 'Массив/Улица'}), required=True)
flat = forms.RegexField(regex=r'^\d+\w+$', error_messages={'invalid':'Invalid Flat'}, label='', widget=forms.TextInput({"placeholder": 'Квартира'}),)
home = forms.RegexField(regex=r'^\d+\w+$', error_messages={'invalid':' Invalid Home'}, label='', widget=forms.TextInput({"placeholder": 'Дом'}),)
contact_number = forms.RegexField(regex=r'^\+?998\d{9,15}$', error_messages={'invalid':'Номер должен начинаться с +998'}, label='', widget=forms.TextInput({"placeholder": 'Контанктный номер '}),)
prefering_connection = forms.DateField(widget=forms.widgets.DateInput(attrs={'type': 'date'}))
tarrif = forms.ChoiceField(choices=Profile.tarrif_plans, label='Тарифный план')`

View: class Edit(UpdateView): model = Profile form_class = ProfileForm template_name = 'edit.html'

1 个答案:

答案 0 :(得分:0)

你应该使用UpdateView的ModelForm而不是forms.Form。

class ProfileForm(forms.ModelForm):
    class Meta:
        model = Profile