﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7918	Allow ForeignKey to a parent class when using inlines	sil	Brian Rosner	"At the moment, if you have a hierarchy:

{{{
class Place(models.Model):
    name = models.CharField(max_length=50)
    address = models.CharField(max_length=80)

class Restaurant(Place):
    serves_hot_dogs = models.BooleanField()
    serves_pizza = models.BooleanField()
}}}

(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:

{{{
class Owner:
    name = models.CharField(max_length=100)
    place = models.ForeignKey(Place)
}}}

(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:

{{{
class OwnerInline(admin.TabularInline): 
    model = Owner
    extra = 5

class PlaceAdmin(admin.ModelAdmin):
    model = Place
    inlines = [OwnerInline]
}}}

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.
"		closed	Database layer (models, ORM)	dev		fixed		arnaud.rebts@…	Accepted	1	1	1	0	0	0
