Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Alexander Schepanovski March 03, 2012
file 36 lines (26 sloc) 0.869 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
VERSION = (0, 1)
__version__ = '.'.join(map(str, VERSION))


from django.db.models import Model
from itertools import izip


def attnames(cls, _cache={}):
    try:
        return _cache[cls]
    except KeyError:
        _cache[cls] = [f.attname for f in cls._meta.fields]
        return _cache[cls]

def model_unpickle(cls, data):
    obj = cls.__new__(cls)
    obj.__dict__.update(izip(attnames(cls), data))
    return obj
model_unpickle.__safe_for_unpickle__ = True

def Model__reduce__(self):
    if self._deferred:
        return original_Model__reduce__(self)
    else:
        cls = self.__class__
        data = self.__dict__.copy()

        vector = map(data.pop, attnames(cls))
        return (model_unpickle, (cls, vector), data)

if Model.__reduce__ != Model__reduce__:
    original_Model__reduce__ = Model.__reduce__
    Model.__reduce__ = Model__reduce__

Something went wrong with that request. Please try again.