6
나머지는 그대로 유지하면서 기본 클래스의 중첩 클래스 멤버 중 일부를 "오버라이드"해야합니다.
이 내가 할 것입니다 :파이썬에서 중첩 된 클래스 멤버를 재정의하는 더 좋은 방법은 무엇입니까?
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
는 사실, 나는 그것의 exclude
튜플이 하나 개 더 항목을 포함해야한다는 점을 제외 InternGenericForm.Meta
같은 정확히, 수 InternApplicationForm.Meta
을합니다.
파이썬에서 더 좋은 방법은 무엇입니까?
오류가 발생하기 쉬운 model = InternGenericForm.Meta.model
과 같은 상용구 코드를 작성하지 않았 으면 좋겠습니다.