On Sun, 2007-10-28 at 20:18 +1100, Malcolm Tredinnick wrote: > On Sun, 2007-10-28 at 08:43 +0000, [EMAIL PROTECTED] wrote: > > Hi Malcolm > > In my design i have a class called publication, that behaves > > different depending on the "state", so i have an state hierarchy that > > implement via polymorphism the different ways the publication behaves. > > I have been reading the djangobook and searching the net, looking a > > way to implement this without lucky. Maybe i'm asking something a lot > > trivial, sorry me if that is the case. > > You can simulate inheritance by using foreign keys or one to one keys. > For example: > > class Parent(models.Model): > some_data = ... > .... > > class Child(models.Model): > parent = models.ForeignKey(parent, unique=True) > ...
I forgot to mention the alternative: storing complex object-oriented hierarchies in SQL databases is officially a Hard Problem. It's just not a natural fit for all cases. So turn your problem around a bit and don't get stuck on one particular modelling method. Instead of storing the classes directly like this, try to think of a way to flatten your collection of classes. For example, if all of you "state nodes" can be stored in a single model somehow, then you only need to store, in addition to these models, the state transitions. Remember, state machines existed long before object-oriented programming. There are other ways to represent the same information without needing polymorphism and this might lead you to a more natural representation. Regards, Malcolm -- The cost of feathers has risen; even down is up! http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---