#30756: ModelForm does not work well with the override field on Inherited Model
-------------------------------------+-------------------------------------
               Reporter:  ramon      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Following the samples:

 {{{
 class City(models.Model):
     name = models.CharField(max_length=100)


 class AddressBase(models.Model):
     city = models.ForeignKey(City, on_delete=models.PROTECT)
     ...
     country = models.ForeignKey(...)

     class Meta:
         abstract = True


 class Address(AddressBase):
     city = models.CharField(max_length=100)


 class AddessForm(forms.ModelForm):
     class Meta:
         model = Address
         fields = ("city", )
 }}}

 I expect a rendered form with the city field as a CharField, but I got the
 following error:

 {{{ Cannot assign "''": "Address.city" must be a "City" instance. }}}

 The problem, I think, is with the code above, on
 models.Field.contribute_to_class

 {{{
         if self.column:
             # Don't override classmethods with the descriptor. This means
 that
             # if you have a classmethod and a field with the same name,
 then
             # such fields can't be deferred (we don't have a check for
 this).
             if not getattr(cls, self.attname, None):
                 setattr(cls, self.attname,
 DeferredAttribute(self.attname))
 }}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30756>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.dceb5b3a04cd650f65069d12bcb761f9%40djangoproject.com.

Reply via email to