[Django] #30756: ModelForm does not work well with the override field on Inherited Model

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #30756: ModelForm does not work well with the override field on Inherited Model

Django
#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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/048.dceb5b3a04cd650f65069d12bcb761f9%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30756: ModelForm does not work well with the override field on Inherited Model

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

 * status:  new => closed
 * resolution:   => duplicate


Comment:

 HI Ramon, this looks like a Duplicate of #30427. (There is
 [https://github.com/django/django/pull/11337 a patch for that] you could
 try. Feedback on the ticket or PR welcome.)

--
Ticket URL: <https://code.djangoproject.com/ticket/30756#comment:1>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.edebc1d8846a68ef790be2f601e534d4%40djangoproject.com.