Changes between Initial Version and Version 3 of Ticket #7918
- Timestamp:
- Jul 23, 2008, 11:50:51 AM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #7918
- Property Patch needs improvement set
- Property Needs documentation set
- Property Needs tests set
-
Ticket #7918 – Description
initial v3 1 1 At the moment, if you have a hierarchy: 2 2 3 {{{ 3 4 class Place(models.Model): 4 5 name = models.CharField(max_length=50) … … 8 9 serves_hot_dogs = models.BooleanField() 9 10 serves_pizza = models.BooleanField() 11 }}} 10 12 11 13 (as per http://www.djangoproject.com/documentation/model-api/#multi-table-inheritance), it doesn't interact all that well with inlined ForeignKeyed models. Imagine you had: 12 14 15 {{{ 13 16 class Owner: 14 17 name = models.CharField(max_length=100) 15 18 place = models.ForeignKey(Place) 19 }}} 16 20 17 21 (so a Place can have multiple Owners). This also works fine with Restaurants, because every Restaurant ''is-a'' Place. However, if you want to inline the Owners: 18 22 23 {{{ 19 24 class OwnerInline(admin.TabularInline): 20 25 model = Owner … … 24 29 model = Place 25 30 inlines = [OwnerInline] 31 }}} 26 32 27 33 then this won't work; if you try and create a Restaurant, you get a complaint that Owner has no ForeignKey to Restaurant (because technically it doesn't). This is because (new)forms._get_foreign_key checks that the ForeignKey points to this model itself, where it should really be checking whether the ForeignKey points to this model ''or any of its ancestor classes''. The attached patch rectifies this. 28