Discussion:
Polymorphic Inheritance
guettli
2014-05-13 18:52:58 UTC
Permalink
I search for a way to get polymorphic inheritance like in "Single table
inheritance" [1]

I have found this comparison site:

https://www.djangopackages.com/grids/g/model-inheritance/

Before I try each, I want to ask here, if someone answer some questions:

I have three classes: Parent, ChildA, ChildB.

The result of Parent.objects.filter() should return Child instances and
should query only one db table.
Unfortunately one one app has filed the column "amount of queries" in the
comparison grid.
What about the other apps?

Next question:

If the class Parent is in the parentapp application, and I want to subclass
this model in a different
application (childapp). The table which belongs to parentapp needs to be
changed: new columns
need to be added. Does south handle the migrations like in the build in
(django core) inheritance solutions?

Why not the build in inheritance solutions? My point of view: multi table
inheritance is slow and with abstract base classes
you can't query the base class. Both solutions are not polymorphic.


[1] http://en.wikipedia.org/wiki/Single_Table_Inheritance
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e1f72be5-e4ec-4e92-a6ca-30507a9bab28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brian Schott
2014-05-13 19:18:51 UTC
Permalink
A good package for what you describe is:
https://github.com/chrisglass/django_polymorphic
http://django-polymorphic.readthedocs.org/en/latest/performance.html
At best this is performing one query per table. This is better than the hand-built solutions which often perform multiple queries per row.

There is a good book called "Two Scoops of Django", which recommends avoiding premature database optimization. Unless you've identified this is the long pole in your tent, you are probably better off focusing on other optimizations such as installing memcached.

Brian Schott
I search for a way to get polymorphic inheritance like in "Single table inheritance" [1]
https://www.djangopackages.com/grids/g/model-inheritance/
I have three classes: Parent, ChildA, ChildB.
The result of Parent.objects.filter() should return Child instances and should query only one db table.
Unfortunately one one app has filed the column "amount of queries" in the comparison grid.
What about the other apps?
If the class Parent is in the parentapp application, and I want to subclass this model in a different
application (childapp). The table which belongs to parentapp needs to be changed: new columns
need to be added. Does south handle the migrations like in the build in (django core) inheritance solutions?
Why not the build in inheritance solutions? My point of view: multi table inheritance is slow and with abstract base classes
you can't query the base class. Both solutions are not polymorphic.
[1] http://en.wikipedia.org/wiki/Single_Table_Inheritance
--
You received this message because you are subscribed to the Google Groups "Django users" group.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e1f72be5-e4ec-4e92-a6ca-30507a9bab28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...