| 124 | |
| 125 | == Proposal #2 (The Original Proposal) == |
| 126 | This would always be enabled. You cannot turn it off. If stuff is broken by having this on then it should be broken. |
| 127 | |
| 128 | This can cause problems with serializers, and things that modify querysets and shouldn't (e.g. .extra). That is the only reason it should be turned off. If those problems are addressed there is no reason to use #17 and to have it enabled 100% of the time. |
| 129 | |
| 130 | A simple workaround querysets, and this would branch into being able to store .values() as partials as well (this code is untested, but should give a general idea): |
| 131 | |
| 132 | {{{ |
| 133 | class SphinxObjectInstance(object): |
| 134 | """ |
| 135 | Acts exactly like a normal instance of an object except that |
| 136 | it will handle any special sphinx attributes in a __sphinx class. |
| 137 | """ |
| 138 | _reserved_attributes = ('_sphinx', '__instance') |
| 139 | |
| 140 | def __init__(self, instance, attributes={}): |
| 141 | object.__setattr__(self, '__instance', instance) |
| 142 | object.__setattr__(self, '_sphinx', SphinxAttributes(attributes)) |
| 143 | |
| 144 | def __setattr__(self, name, value): |
| 145 | if name in _reserved_attributes: |
| 146 | return object.__setattr__(self, name, value) |
| 147 | return setattr(self.instance, name, value) |
| 148 | |
| 149 | def __getattr__(self, name, value=None): |
| 150 | if name in _reserved_attributes: |
| 151 | return object.__getattr__(self, name, value) |
| 152 | return getattr(self.instance, name, value) |
| 153 | }}} |
| 154 | |
| 155 | The proposal would also change how extra is used, it should probably be instance._extra or something similar. |
| 156 | |
| 157 | (The code above is taken from an unpublished update to the django-sphinx package.) |