Opened 8 years ago

Closed 8 years ago

#6931 closed (invalid)

Backward relationships are overidden when Models Inherit

Reported by: Jurian Botha <jurianbotha@…> Owned by: nobody
Component: Database layer (models, ORM) Version: queryset-refactor
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When a model contains a reference another model and is then extended, calling the 'related_name' attribute of the referenced model only returns the related objects of the model that was last declared.

class Town(models.Model):
 name = models.CharField(max_length=255)

class Place(models.Model):
 town = models.ForeignKey(Town, related_name="places")
 address = models.CharField(max_length=255)

class Store(Place):
 cuisine = models.Charfield()

Now if I add the following data:

london = Town(name='London')

placeA = Place(town=london, address='fake address A')

placeB = Place(town=london, address='fake address B')

resturantA = Resturant(town=london, address='fake address C', cuisine='bytes')

and then check the output of the following:


it only returns the object 'resturantA' and doesn't include 'placeA' or 'placeB'.

Change History (5)

comment:1 Changed 8 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from newforms-admin to queryset-refactor

Fixing the version, since model inheritance doesn't exist in newforms-admin.

comment:2 Changed 8 years ago by Jurian Botha <jurianbotha@…>

I am using newforms-admin though. And it seems to me that it's working.

It creates three independent tables.

comment:3 Changed 8 years ago by Jurian Botha <jurianbotha@…>

Please note that I mean 'Model Inheritance' is working, but the issue mentioned initially is still not resolved.

comment:4 Changed 8 years ago by Alex

Model inheritance decidedly does not exist in newforms-admin, either you have made a mistake in your version, or it only appears to be working. I am going to close this, if it turns out that you just mistaked the version(or this bug actually does exist in queryset-refactor) feel free to reopn.

comment:5 Changed 8 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

There's a big difference between "creates three tables" and "works". The main problem is that the model manager will not be correct in child models which leads to all sorts of problems.

Closing this as invalid, since it's not something that is expected to work in newforms-admin and now that I read the bug, it's turns out to be something that the model inheritance tests are testing (in the queryset-refactor branch).

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