django-typed-models - sane single-table model inheritance

98 views
Skip to first unread message

Craig de Stigter

unread,
Feb 19, 2012, 4:12:57 PM2/19/12
to django...@googlegroups.com
In May last year I posted this topic on django-developers.

We wanted a way to do proxy-model inheritance, while preserving the type of each object when it goes in and out of the database.

Unable to find anything that did what I wanted, I wrote my own! It was basically finished by June last year but I finally open-sourced it:


Basically you can just define a base model, with database fields, and then inherit from it as much as you want. The inherited models all become proxy models - they only define in-python behavior, they can't define database fields.

Everything gets stored in one table, and retrieving objects from the database will result in them having the correct model class. A single queryset of a superclass might result in the retrieval of multiple types of subclasses, all in one query.

See the readme on that github link for an example. Please let me know what you think! And file issues if you have some.

Cheers

Craig de Stigter
Koordinates Ltd
Reply all
Reply to author
Forward
0 new messages