﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27883	"""Vertical"" polymorphism of models"	Victor Porton	nobody	"https://docs.djangoproject.com/en/1.10/ref/contrib/contenttypes/ describes what I call ""horizontal"" polymorphisms of models: an object is identified by both model name and ID.

I want ""vertical"" polymorphism where an object is identified by its sole ID. (It is in some aspects better, as for vertical polymorphisms such things as unique IDs (and thus one-to-one relations) make sense, which are harder to implement with horizontal polymorphism.)

More precisely, I want `PolymorphicModel` usable as follows:

{{{
class MyModel(models.PolymorphicModel):
    klass = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    # more fields
}}}

Now we can have derived one-to-one models like.

{{{
class DerivedModel(MyModel):
    # more fields
    ...
}}}

Next we could retrieve the model object using a `models.PolymorphicModel` class method:

{{{
obj = MyModel.polymorphic_retrieve(pk)
}}}

This needs two DB read operations: One to get the `klass` and yet one to read the specific descendant model.

I may attempt to formulate this precisely and to write the code, but I am not particularly strong in Django internals.

It is a very important features which can find many usages."	New feature	closed	Database layer (models, ORM)	1.10	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
