Opened 18 years ago

Closed 17 years ago

#978 closed defect (invalid)

STACKED ForeignKey classes don't show up in the admin for subclasses of related class

Reported by: Arthur Hebert Owned by: nobody
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is a simple problem that can be reproduced within one small model. I have five classes; one of them, Entity, is basically used as an abstract class, and is subclassed by Company and Person. The two remaining classes are PhoneNumber and Email, which are simple OneToMany relationships that point to Entity. In the call to ForeignKey(), I specify that PhoneNumber and Email should have edit_inline=meta.STACKED, however, they do not show up in the admin interface for either Company or Person. I really believe that they should show up.

Here is the model code:

#####################################################
from django.core import meta

class Entity(meta.Model):
	# phones and emails are referenced to this class
	address = meta.TextField()
	notes = meta.TextField()
class PhoneNumber(meta.Model):
	entity = meta.ForeignKey(Entity, edit_inline=meta.STACKED, num_in_admin=2)
	number = meta.CharField(maxlength=20, core=True)
class Email(meta.Model):
	"""An email address"""
	entity = meta.ForeignKey(Entity, edit_inline=meta.STACKED, num_in_admin=1)
	email = meta.EmailField(core=True)
class Company(Entity):
	name = meta.CharField(maxlength=200)
	
	def __repr__(self):
		return self.name
	
	class META:
		admin = meta.Admin()
class Person(Entity):
	company = meta.ForeignKey(Company)
	
	first_name = meta.CharField(maxlength=30, core=True)
	last_name = meta.CharField(maxlength=30, core=True)
	
	def __repr__(self):
		return "%s %s" % (self.first_name, self.last_name)
	
	class META:
		admin = meta.Admin()
######################################################

It is structured this way, because there is no point in entering an Email or PhoneNumber outside the context of an Entity, and it would be redundant to apply separate relationships to Company and Person classes, because they are inherently alike. Feel free to email me if I can clarify: funnylukin--at--yahoo--dot--com. I am still new to django (and python), so I don't have deeper insight into the source of the problem.

Change History (4)

comment:1 by rjwittams, 18 years ago

Resolution: fixed
Status: newclosed

Inheritance works in a very odd way currently in Django - it copies the fields and messes around with them, and in general does not act like a real subclass.
It is on the roadmap for 1.0 to fix this in a satisfactory way - search for the message 'Semantics of Subtyping' on the django-developers google group.

comment:2 by rjwittams, 18 years ago

Resolution: fixed
Status: closedreopened

comment:3 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedDesign decision needed

Are subclassed models still in the future of Django?

comment:4 by James Bennett, 17 years ago

Resolution: invalid
Status: reopenedclosed

The model-subclassing code has been removed from Django and the admin interface (meaning the implementation of edit_inline) is being deprecated and replaced; marking invalid.

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