﻿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
7488	Inline forms break when the foreign model does not inherit directly from models.Model	mkibbel@…	Brian Rosner	"This sample code example demonstrates the problem:
{{{
#!python
from django.db import models
from django.contrib import admin

class Base(models.Model):
   base_name = models.CharField(
      ""Base Name"",
      max_length = 40,
   )

class Child(Base):
   child_name = models.CharField(
      ""Child Name"",
      max_length = 40,
   )

class Inline(models.Model):
   child = models.ForeignKey(
      Child,
   )
   inline_name = models.CharField(
      ""Inline Name"",
      max_length = 40,
   )

class InlineAdmin(admin.StackedInline):
   model = Inline

class ChildAdmin(admin.ModelAdmin):
   inlines = (InlineAdmin,)

try:
   admin.site.register(Child, ChildAdmin)
except admin.sites.AlreadyRegistered:
   pass
}}}
When the admin's add_view for the ""Child"" class runs, a DoesNotExist exception is raised. If any of the following changes is made, the problem does not present itself:

 * removing the ""edit_inline"" functionality by removing ""inlines"" from ChildAdmin (not an acceptable workaround)
 * making the Child model inherit from models.Model (better, but still very inconvenient)

I traced the problem back to the get_query_set function in django.newforms.models.BaseInlineFormset, which reads as such:
{{{
#!python
    def get_queryset(self):
        """"""
        Returns this FormSet's queryset, but restricted to children of 
        self.instance
        """"""
        kwargs = {self.fk.name: self.instance}
        return self.model._default_manager.filter(**kwargs)
}}}
Here, self.instance == Child(), an unsaved Child model instance (with no primary key), so the resulting call to filter is looking up an Inline object by an undefined primary key on the Child object. I have no idea why this problem does not present itself when Child inherits from models.Model, but I do have a simple patch to fix this bug."		closed	Core (Other)	dev		fixed	model inheritance		Accepted	1	0	0	1	0	0
