Django

Code

Changeset 6917

Show
Ignore:
Timestamp:
12/12/07 21:14:31 (7 months ago)
Author:
jkocherhans
Message:

Changed ModelForms? to allow inheritance as long as their model attributes are the same.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/models.py

    r6915 r6917  
    246246        # If a model is defined, extract form fields from it and add them to base_fields 
    247247        if attrs['_meta'].model is not None: 
    248             # Don't allow a subclass to define a Meta model if a parent class has. 
    249             # Technically the right fields would be generated, but the save  
    250             # method will not deal with more than one model. 
     248            # Don't allow a subclass to define a different Meta model than a 
     249            # parent class has. Technically the right fields would be generated, 
     250            # but the save method will not deal with more than one model. 
    251251            for base in bases: 
    252252                base_opts = getattr(base, '_meta', None) 
    253253                base_model = getattr(base_opts, 'model', None) 
    254                 if base_model is not None
    255                     raise ImproperlyConfigured('%s defines more than one model.' % name) 
     254                if base_model and base_model is not opts.model
     255                    raise ImproperlyConfigured('%s defines a different model than its parent.' % name) 
    256256            model_fields = fields_for_model(opts.model, opts.fields, opts.exclude) 
    257257            # fields declared in base classes override fields from the model 
  • django/trunk/tests/modeltests/model_forms/models.py

    r6915 r6917  
    144144Traceback (most recent call last): 
    145145... 
    146 ImproperlyConfigured: BadForm defines more than one model
     146ImproperlyConfigured: BadForm defines a different model than its parent
    147147 
    148148>>> class ArticleForm(ModelForm): 
     
    155155... 
    156156ImproperlyConfigured: BadForm's base classes define more than one model. 
     157 
     158This one is OK since the subclass specifies the same model as the parent. 
     159 
     160>>> class SubCategoryForm(CategoryForm): 
     161...     class Meta: 
     162...         model = Category 
    157163 
    158164