Changes between Version 2 and Version 3 of DynamicModels
- Timestamp:
- May 9, 2007, 2:57:10 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DynamicModels
v2 v3 8 8 == The basic technique == 9 9 10 Internally, Django uses metaclasses to create models based on a class you provide in your source code. Without getting into too many details, that means that rather than your classes being the actual models, Django receives a description of your class, which it uses to create a model in its place. 10 Internally, Django uses metaclasses to create models based on a class you provide in your source code. Without getting into too many details, that means that rather than your classes being the actual models, Django receives a description of your class, which it uses to create a model in its place. For more details, see the writeup on [wiki:DevModelCreation Model Creation]. 11 11 12 12 Thankfully, Python treats classes like any other object, so we can force this process to occur even when the class wasn't defined in source. All we really need is to give Django a description of a class, and let it do all the work of creating the model for us. Here's some bare-bones code.