We're pleased to announce the first alpha release of a new package, djeneralize, to augment the model inheritance available in Django. djeneralize allows you to define specializations of general case models and then have these specializations returned from querying the database. For example:
>>> Fruit.objects.all() [<Fruit: Rosy apple>, <Fruit: Bendy banana>, <Fruit: Sweet clementine>] >>> Fruit.specializations.all() [<Apple: Rosy apple>, <Banana: Bendy banana>, <Clementine: Sweet clementine>]
This allows all the fruit in the database to be returned as the specialized fruit model instances rather than general Fruit model instances. We hope this functionality will allow the grouping of content types with common fields and allow rapid access to the specific model instances so that list views can be easily built which reflect the diversity of specialized content.
djeneralize handles all the database lookups that you would need to perform behind the scenes and allows the vast majority of Django query syntax to be used. It supports multiple-levels of specialization to allow querying of sub-generalizations.
We are planning on integrating this work into a current project to allow fine-grained categorization of all content on the 2degrees platform and hope this will offer us all the power and flexibility we need.
To get djeneralize either clone the source from github, or install it via
$ easy_install djeneralize
Further information and full documentation is also available.