Ticket #7837: forms_metaclass_hierarchy_problem_fix_r8335.diff
File forms_metaclass_hierarchy_problem_fix_r8335.diff, 2.4 KB (added by , 16 years ago) |
---|
-
django/forms/models.py
168 168 169 169 if 'media' not in attrs: 170 170 new_class.media = media_property(new_class) 171 declared_fields = get_declared_fields(bases, attrs, False) 171 if attrs.has_key('declared_fields'): 172 declared_fields = attrs['declared_fields'] 173 else: 174 declared_fields = SortedDict() 175 declared_fields.update(get_declared_fields(bases, attrs, False)) 172 176 opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None)) 173 177 if opts.model: 174 178 # If a model is defined, extract form fields from it. -
django/forms/forms.py
56 56 'base_fields', taking into account parent class 'base_fields' as well. 57 57 """ 58 58 def __new__(cls, name, bases, attrs): 59 attrs['base_fields'] = get_declared_fields(bases, attrs) 59 declared_fields = get_declared_fields(bases, attrs) 60 attrs['declared_fields'] = declared_fields 61 attrs['base_fields'] = declared_fields 60 62 new_class = super(DeclarativeFieldsMetaclass, 61 63 cls).__new__(cls, name, bases, attrs) 62 64 if 'media' not in attrs: -
tests/regressiontests/forms/models.py
73 73 datetime.date(1969, 4, 4) 74 74 >>> instance_form.initial['value'] 75 75 12 76 77 78 # Regression test for #7837 ################################################## 79 80 Make sure hierarchy in metaclasses doesn't miss declared fields 81 82 >>> class ExtraFieldForm(django_forms.Form): 83 ... extra_field = django_forms.CharField() 84 85 >>> class ChildForm(ExtraFieldForm, ModelForm): 86 ... # this is necessary to avoid python metaclass conflict error 87 ... __metaclass__ = type('ChildFormMetaclass', (ExtraFieldForm.__metaclass__, django_forms.ModelForm.__metaclass__), {}) 88 ... non_existing_field = django_forms.CharField() 89 ... class Meta: 90 ... model = ChoiceModel 91 92 >>> ChildForm.base_fields.keys() 93 ['name', 'extra_field', 'non_existing_field'] 76 94 """}