2016-10-10 26 views
0

私が持っている問題は、追加した1つのフィールドです。Django 1.9フォームの継承がUpdateViewで

私は自分のフォームを持っている:私のモデルでは



    class employeesForm(forms.ModelForm): 
     class Meta: 
      fields = [ 
       'num_employee', 
       'id_ignition', 
       'fullName', 
       'shortName', 
       'salary', 
       'gender', 
       'rfc', 
       'imss', 
       'curp', 
       'birthday', 
       'initday', 
       'id_costCenter', 
       'id_jobCode', 
       'id_status', 
       'nationality', 
       'picture', 
       'source', 
      ] 


      widgets = { 
       'num_employee': forms.NumberInput(attrs={'class': 'form-control', 'name': 'num_employee'}), 
       'id_ignition': forms.NumberInput(attrs={'class': 'form-control', 'name': 'id_ignition'}), 
       'fullName': forms.TextInput(attrs={'class': 'form-control', 'name': 'fullName', 'placeholder': 'Angel Rafael Ortega Vazquez'}), 
       'shortName': forms.TextInput(attrs={'class': 'form-control', 'name': 'shortName', 'placeholder': 'Rafael Ortega'}), 
       'salary': forms.NumberInput(attrs={'class': 'form-control', 'name': 'salary', 'placeholder': '5000'}), 
       'gender': forms.CheckboxInput(attrs={'class': 'form-control', 'name': 'gender'}), 
       'rfc': forms.TextInput(attrs={'class': 'form-control', 'name': 'rfc', 'id': 'rfc'}), 
       'imss': forms.TextInput(attrs={'class': 'form-control', 'name': 'imss', 'id': 'imss'}), 
       'curp': forms.TextInput(attrs={'class': 'form-control', 'name': 'curp'}), 
       'birthday': forms.DateInput(attrs={'class': 'form-control', 'name': 'birthday'}), 
       'initday': forms.DateInput(attrs={'class': 'form-control', 'name': 'initday'}), 
       'id_costCenter': forms.Select(attrs={'class': 'form-control', 'name': 'id_costCenter'}), 
       'id_jobCode': forms.Select(attrs={'class': 'form-control', 'name': 'id_jobCode'}), 
       'id_status': forms.Select(attrs={'class': 'form-control', 'name': 'id_status'}), 
       'nationality': forms.Select(attrs={'class': 'form-control', 'name': 'nationality'}), 
       'picture': forms.ClearableFileInput(attrs={'class': 'form-control', 'name': 'picture'}), 
       'source': forms.Select(attrs={'class': 'form-control', 'name': 'source'}), 
      } 

私CREATEVIEWに、私は他のパラメータ(古代=に基づいて、そのフィールドを埋めるので、私は余分なフィールド(古代)を持っていますが、私はここでそれを無視しています開始日)。私は、余分なフィールド前の人口とUpdateViewを作成するために必要になるまで

すべては私がやったことはプレビューの形式とは、余分なフィールドを追加することを継承した、うまく働いた:



    class Enhanced_employeesForm(employeesForm): 

     antiquity = forms.CharField(
      widget=forms.DateInput(attrs={'class': 'form-control', 'name': 'antiquity'})) 

それは事をしました、入力フィールドはテンプレートに表示されますが、idに基づいた情報がすべて事前に設定されていますが、古代フィールドは空です。

そのフィールドが上空の場合ジャンゴでも検出するので、私は私の構成で欠けているだけのことだ

提出すると私は同じような何かをやってみましたデータベース

に任意の更新を防ぐ:

form.antiquity(instance=Employees.objects.get(pk=self.kwargs['pk'])) 

しかし、 'Enhanced_employeesForm'オブジェクトには '古さ'という属性はありません。私は間違ったことをしていた

答えて

0

、私は私の強化フォームにこのコードを追加する必要がありました:

class Enhanced_employeesForm(employeesForm): 
    class Meta(employeesForm.Meta): 
     employeesForm.Meta.fields += ['antiquity'] 

、それは事をしました。

あなたがウィジェットを必要とする場合は、あなたがこれを必要とするだろうことを防ぐために、すべてが上書きされていることに気づいたかもしれません:

employeesForm.Meta.widgets['antiquity'] = forms.DateInput(attrs={'class': 'form-control'}) 
関連する問題