मुझे कुछ बेस क्लास 'नेस्टेड क्लास के सदस्यों को "ओवरराइड" करने की ज़रूरत है, जबकि बाकी बरकरार रहें।
यह मैं क्या कर रहा है:पायथन में नेस्टेड क्लास सदस्यों को ओवरराइड करने का बेहतर तरीका क्या है?
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
टपल एक और सूची आइटम शामिल करना चाहिए।
पायथन में ऐसा करने का एक और सुंदर तरीका क्या है?
मेरी इच्छा है कि मुझे model = InternGenericForm.Meta.model
जैसे बॉयलरप्लेट कोड लिखने की आवश्यकता नहीं है जो त्रुटियों के लिए भी प्रवण है।