Inheritance

1 view
Skip to first unread message

Narso

unread,
Dec 24, 2007, 7:21:11 AM12/24/07
to Django users
Hi. Forgive my poor English.

I have a lot of models for classifications. All of them have similar
attributes. When I try to use inheritance in the models design, the
admin interface doesn't work with ForeignKey fields.

Example:

class BasicModel(models.Model):
name=models.CharField(maxlength=30)
def __str__(self):
return self.name

class Reference(BasicModel):
class Admin:
pass

class Data(BasicModel):
ref = models.ForeingKey(Reference)
class Admin:
pass

Here, the ref field doesn't show all of their records in the Admin Add
Data form.

Empty

unread,
Dec 24, 2007, 9:35:41 AM12/24/07
to django...@googlegroups.com

You will likely run into all kinds of problems. Model Inheritance is
currently not supported in Django. There has been discussions and
proposals on the topic so I suspect that it will be available at some
point. See here:

http://code.djangoproject.com/wiki/ModelInheritance

Michael Trier
blog.michaeltrier.com

Toby Dylan Hocking

unread,
Dec 27, 2007, 1:30:47 PM12/27/07
to django...@googlegroups.com

Also you may try to use multiple inheritance, which has worked for me for
extending models, i.e.

class YourModel(YourOtherModel,models.Model):

Not sure if it will work for your purpose, but give it a try!

Reply all
Reply to author
Forward
0 new messages