Changes between Version 16 and Version 17 of DjangoSpecifications/Core/SingleInstance
- Timestamp:
- Mar 25, 2008, 6:04:51 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DjangoSpecifications/Core/SingleInstance
v16 v17 115 115 116 116 === Discussion === 117 The current patch design overrides the __ call__ method for the model base which means it magically returns singleton instances when available. This is convenient because XXX (David or Brian: feel free to fill this out).117 The current patch design overrides the ____call____ method for the model base which means it automatically returns singleton instances when available. This is convenient because XXX (David or Brian: feel free to fill this out). 118 118 119 Another approach would be to skip the magicand have a simple API along the lines of:119 Another approach would be to make this explicit and have a simple API along the lines of: 120 120 {{{ 121 121 class ModelBase: … … 124 124 125 125 }}} 126 That means writing Model(kwargs) would always return a fresh instance and bypass theinstance. Since Django's ORM would use the API internally, doing Model.objects.get would (by default, overridable in the manager) return the singleton. The default related manager would also have a new get_from_db method to force retrieving and instantiating from the DB only.126 That means writing Model(kwargs) would return a freshly instantiated object (as is the case now) and bypass the singleton instance. Since Django's ORM would use the API internally, doing Model.objects.get would (by default, overridable in the manager) return the singleton. The default related manager would also have a new get_from_db method to force retrieving and instantiating from the DB only. 127 127 128 128 == (The Original Proposal) ==