6
基本クラスのネストされたクラスメンバのいくつかを "オーバーライド"し、残りはそのまま維持する必要があります。
これは私が何をすべきかです:Pythonでネストされたクラスメンバーをオーバーライドするにはどうすればよいでしょうか?
class InternGenericForm(ModelForm):
class Meta:
model = Intern
exclude = ('last_achievement', 'program',)
widgets = {
'name': TextInput(attrs={'placeholder': 'Имя и фамилия' }),
}
class InternApplicationForm(InternGenericForm):
class Meta:
# Boilerplate code that violates DRY
model = InternGenericForm.Meta.model
exclude = ('is_active',) + InternGenericForm.Meta.exclude
widgets = InternGenericForm.Meta.widgets
、私はInternApplicationForm.Meta
が正確InternGenericForm.Meta
のような、そのexclude
タプルが1つのより多くの項目を含まなければならないことを除いてになりたいです。
これをPythonで行うもっと美しい方法は何ですか?
model = InternGenericForm.Meta.model
のような定型コードを記述する必要はなく、エラーが発生しやすいと思います。