On Mon, 2008-02-18 at 03:06 -0800, Jiri Barton wrote: > The infamous commit #7126 seems to obsolete generic relations -- to > me. > > class ContentType(models.Model): > class Meta: > abstract = True > > class TaggedItem(models.Model): > content_object = models.ForeignKey(ContentType) > > The just introduced model inheritance will even let me include fields > common to ContentType descendant. I was just curios if, > > I understand this correctly and, > > which will be the preferred way.
Not at all. Models with abstract=True do not really exist. They are a way to carry around common information. However, when they are created part of a subclass, their information is made part of that subclass. You cannot do a query against an abstract model. It knows nothing about what classes it's part of (in fact, even normal model inheritance knows nothing about its child classes -- it's only when you try to access a child that it does the query to work out if there is a child of the class you refer to). One of the problems the commit message referred to that I'm working on is avoiding people trying to abuse abstract classes like this. Python has a requirement that the metaclass of any class must be a superset of the parent metaclasses, so giving abstract base classes a different metaclass makes things a bit more fiddly for child classes. It's probably going to turn out that if you do things like this, you'll get to keep both pieces after it breaks. Leaping through ridiculous numbers of hoops to stop this might not be worth it, but it's something I'm still working on. So, no. Model inheritance is quite different from generic relations. In fact, they're opposites. Generic relations provide a way to push from the general to the specific in situations where you're driving things from the general class (the one containing the generic relation). Model inheritance provides a way to pull the more general parent classes into a more specific child class where you'll normally be working with the child. Regards, Malcolm -- Always try to be modest and be proud of it! http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
