Celery v0.8.1 (stable) documentation
Custom Django Model Fields.
A subclass of string so it can be told whether a string is a pickled object or not (if the object is an instance of this class then it must [well, should] be a pickled one).
Only really useful for passing pre-encoded values to default with dbsafe_encode, not that doing so is necessary. If you remove PickledObject and its references, you won’t be able to pass in pre-encoded values anymore, but you can always just pass in the python objects themselves.
A field that will accept any python object and store it in the database. PickledObjectField will optionally compress it’s values if declared with the keyword argument compress=True.
Does not actually encode and compress None objects (although you can still do lookups using None). This way, it is still possible to use the isnull lookup type correctly. Because of this, the field defaults to null=True, as otherwise it wouldn’t be able to store None values since they aren’t pickled and encoded.
Pickle and b64encode the object, optionally compressing it.
The pickling protocol is specified explicitly (by default 2), rather than as -1 or HIGHEST_PROTOCOL, because we don’t want the protocol to change over time. If it did, exact and in lookups would likely fail, since pickle would now be generating a different string.
Returns the default value for this field.
The default implementation on models.Field calls force_unicode on the default, which means you can’t set arbitrary Python objects as the default. To fix this, we just return the value without calling force_unicode on it. Note that if you set a callable as a default, the field will still call it. It will not try to pickle and encode it.
B64decode and unpickle the object, optionally decompressing it.
If an error is raised in de-pickling and we’re sure the value is a definite pickle, the error is allowed to propogate. If we aren’t sure if the value is a pickle or not, then we catch the error and return the original value instead.
We use deepcopy() here to avoid a problem with cPickle, where dumps can generate different character streams for same lookup value if they are referenced differently.
The reason this is important is because we do all of our lookups as simple string matches, thus the character streams must be the same for the lookups to work properly. See tests.py for more information.