Ticket #326 (closed defect: fixed)

Opened 6 years ago

Last modified 4 years ago

problems with orm and multi-table inheritance

Reported by: bas@… Owned by: andrew
Priority: major Milestone: 0.7
Component: migrations Version: 0.6.2
Keywords: inheritance orm Cc:



I'm trying to do some data migration using model class (for example, Restaurant) that inherits from other non-abstract model (for example, Place) in a multi-table inheritance mode. In South migration file I do:

   restaurants = orm.Restaurant.filter(field1='blabla')

If field1 belongs to Restaurant model then it works just fine. But if field1 belongs to Place then that line fails with:

django.core.exceptions.FieldError: Cannot resolve keyword 'field1' into field. Choices are: ...Restaurant only fields listed here...

It works perfectly in real Django orm world.

Let me know if you need me to attach a real example.

Thank you.

Change History

comment:1 Changed 6 years ago by bas@…

I found a workaround,

If parent_link in Restaurant (OneToOneField? link to base Place model) is defined as:

place = models.OneToOneField(Place, related_name='restaurant', parent_link=True)

and you want to filter by Place's field1 just do:

restaurants = orm.Restaurant.filter(place__field1='blabla')

It works to any level of inheritance.

Anyway, it would be good to replicate how Django handles base model fields filtering in South.

comment:2 Changed 6 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.7

Yes, I think this is another slight imperfection of the ORM. I'll schedule it for fixing in the upcoming 0.7.

comment:3 Changed 6 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

This has been fixed along with #182 in [237ca3bb6d5d].

Note: See TracTickets for help on using tickets.