Hi Joakim, On 03 Mar 2016, at 11:03, Joakim Saario <[email protected]> wrote:
> The problem is that django hijacks the class-inheritance feature of python > and uses it soley > for relational inheritance. I understand that you would like each model class to have its own table with all its fields, whether they’re defined in this class or in a superclass. However, according to the regular OOP model, Django considers that children ORM classes specialize their parent class. You must be able to take a child instance and cast it to a parent instance by throwing away attributes not used in the parent and using the parent’s methods. In other words, if Child.objects.get(pk=1) works, Parent.objects.get(pk=1) is supposed to give you a Parent instance that is a more generic version of the Child instance. (I have to admit that this isn’t always true with Django. If the Parent is abstract, Parent.objects.get will raise an exception.) My main concern with your proposal is that Parent.objects.get(pk=1) would return an object that is totally unrelated to Child.objects.get(pk=1)! I have a hard time believing this qualifies as “regular class inheritance”. I suspect many Python programmes would find it surprising. That is why Django cannot ignore the fact that an ORM model is backend by a database table. It needs to decide what table to use — or disable database access entirely to avoid this problem. I’m sorry if this feels like “hijacking” to you. It’s prevents data corruption bugs, though. Best regards, -- Aymeric. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1A4487D5-6918-40FA-B3E0-29A24B2D7CE0%40polytechnique.org. For more options, visit https://groups.google.com/d/optout.
