On 12/14/06, Crispin Bennett <[EMAIL PROTECTED]> wrote: > > My first experiment with Django is a kind of wiki that involves being > able to add a variety of different types of pages, each with their own > set of fields. The obvious way to do this would be to create a base > model page class which various page types inherit. But I can't imagine > how the Django ORM layer handles this. > > Would I be barking up the wrong tree?
Yes and No. Django does have the ability to do a sort of model inheritance, using OneToOneFields. This establishes a 1-1 relationship between a base class and a child class. For example: class Base(Model): name = CharField() class Article(Model): base = OneToOneField(MyBase) length = IntegerField() class Author(Model): base = OneToOneField(MyBase) age = IntegerField() In this case, each Article is required to reference a single Base instance (likewise for Author). An article instance can ask for base.name to get the name of the article; author.base.name will give the name of the author. Obviously, this is less than ideal, and there are a few gotchas - for example, you have to manually create the base class instances. However, it does work. There is a work-in-progress to add a more formal inheritance structure to Django - search the developers archives and the wiki for a detailed discussion of the form this inheritance will take. This work is being performed by Malcolm Treddinick. Last time I heard from him, he was close, but not quite finished, and there were a few issues in other areas holding him up. However, he's been a bit quiet of late. Malcolm? You still out there? How goes the struggle? Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---