Opened 6 years ago

Closed 6 years ago

#19561 closed Uncategorized (invalid)

Through-table model attributes are not available

Reported by: qcwxezdas@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5-beta-1
Severity: Normal Keywords: orm, many-to-many, through
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Here's my code:

class Property(models.Model):
    title = models.CharField(_("Title"), max_length=150, unique=True)
    default_description = models.TextField(_("Default description"), blank=True)

class AccommodationProperty(models.Model):
    accommodation = models.ForeignKey("Accommodation")
    prop = models.ForeignKey(Property, verbose_name=_("Property"),

    custom_description = models.TextField(_("Custom description"), blank=True)

class Service(models.Model):
    title = models.CharField(_("Title"), max_length=150)

class Accommodation(Service):
    properties = models.ManyToManyField(Property, through=AccommodationProperty,
                                        related_name="accommodations", blank=True)

And here's what's wrong:

>>> acprop = AccommodationProperty.objects.all()[0]
>>> acprop.accommodation
<Accommodation: test apgyv>
>>> acprop.prop
<Property: Internetas>
>>> acprop.custom_description
>>> acprop.prop.default_description
>>> ac = acprop.accommodation
[<Property: Internetas>]
>>> prop =[0]
>>> prop.default_description
>>> prop.title
>>> prop.custom_description
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Property' object has no attribute 'custom_description'

Attribute custom_description cannot be accessed.

Change History (2)

comment:1 Changed 6 years ago by qcwxezdas@…

Component: ORM aggregationDatabase layer (models, ORM)

comment:2 Changed 6 years ago by Ramiro Morales

Resolution: invalid
Status: newclosed

In your sample code, prop is an instance of the Property model. and Property has no custom_description field.

Note: See TracTickets for help on using tickets.
Back to Top