def get_db_prep_value(self, value, connection=None, prepared=False):
        if value is not None and not isinstance(value, PickledObject):
            # We call force_unicode here explicitly, so that the encoded string
            # isn't rejected by the postgresql_psycopg2 backend. Alternatively,
            # we could have just registered PickledObject with the psycopg
            # marshaller (telling it to store it like it would a string), but
            # since both of these methods result in the same value being stored,
            # doing things this way is much easier.
            value = force_unicode(dbsafe_encode(value, self.compress, self.protocol))
        return value
Pickle and b64encode the object, optionally compressing it.
dataset/ETHPy150Open callowayproject/django-supertagging/supertagging/fields.py/PickledObjectField.get_db_prep_value