Hi Aaron,

I know there're two way to use model inheritance with current django.
both are not perfect, you could choice what you need. That's say model
inheritance is still not a feature of django, but should be one imo.

1. as you said, use OneToOne field
       class Place(models.Model):
           name = models.CharField(maxlength=50)

       class Restaurant(models.Model):
           place = models.ForeignKey(Place)
           type_of_food = models.CharField(maxlength=50)

The problems are:
 * very hard to use it will Admin interface. Current Admin only
support edit_inline, that means edit Restaurant in Place, but what you
need it's kind of "edit_outline" -- edit Place in Restaurant.
 * without OO inheritance power, you need remeber which field in
Place, which field in Restaurant.

2. use OO inheritance, current django support inheritance model --
inheritance all parent fields to child.
       class Place(models.Model):
           name = models.CharField(maxlength=50)

       class Restaurant(Place):
           type_of_food = models.CharField(maxlength=50)
       # fix default manager
       _default_manager = Model.Manager()
      _default_manager.model = Restaurant
       Restaurant._default_manager= Restaurant.objects =
_default_manager

the way is firendly to Admin and easy to search.
The problems are:
 * default manager don't work, you have to fix it outside the classs
definition.
 * restautant have parents all fields in database. that's not a
problem for us.

1. If I ask for a list Places matching certain criteria, then Hotels,
Restaurants, and basic Places matching the criteria should all be
returned.
In second way need sync the child field with the base instance.


2. If I get a list of Places as above, then I should be able to tell
whether a given object in the list is a Hotel or Restaurant or whatever
and get and set its associated properties.

In both way, you have to have a genericFK in base model(point to child
instance), and maintain it when call child.save. so you can return a
base model queryset and regroup them by content_type.

3. Restaurants and Hotels should be their own independent entities.  If
there is some crazy stuff going on with foreign keys and multiple
tables behind the scenes, it should stay behind the scenes as an
implementation detail.  So if I delete a Hotel object, it should
automatically delete the associated Place object if there is such a
thing in the implementation.
In both way you have to do it yourself, but you could use signals have
you to do it automatically.

I can see there're more ways described in[1], but seems those way have
it own problems. you could try.


[1] http://code.djangoproject.com/wiki/ModelInheritance


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to