-
Notifications
You must be signed in to change notification settings - Fork 16
Extensible Models
czue edited this page Sep 14, 2010
·
1 revision
The ExtensibleModelBase class lets you define models that link to other models, creating a chain of inheritance. By defining django models in:
/extensions/[app_to_extend]/[model_to_extend].py
you can get new top-level properties on the object.
In order for your base model class to support this you must add the following line:
metaclass = ExtensibleModelBase
Additionally the django models defined in the file should be declared abstract, since they won’t be instantiated.
See the Contact model in the rapidsms core for an example of a model that can be extended, and the contact.py file in the locations/extensions/rapidsms contrib app folder for an example of it being extended. The end result of these two classes is that a .location is available on instances of Contact models as a foreign key to the Location table.