1
ChoiceFieldをサブクラス化して複数のフォーム(DRY)で使用できるようにしようとしています。たとえば:django choicefieldのサブクラス化が機能しない
で_choices
として
choices
を指定
AttributeError at /..url.../
'testField' object has no attribute '_choices'
:
class testField(forms.ChoiceField):
choices = (('a', 'b'), ('c', 'd'))
label = "test"
class testForm(forms.Form):
test = testField()
フィールドの他のタイプのChoiceFieldのサブクラスをレンダリングするときしかし、私はあいまいなエラーを取得し、(例えばCharFieldですなど)のサブクラスとして働きますサブクラスはエラーを報告しませんが、レンダリングの内容を表示しません。
- 感謝を – dwagon