VERSION = (0, 2)
__version__ = '.'.join(map(str, VERSION))


from django.db.models import Model
try:
    from itertools import izip
except ImportError:
    izip = zip


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 = [data.pop(name) for name in attnames(cls)]
        return (model_unpickle, (cls, vector), data)

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


@@ -537,91 +537,8 @@
 f):%0A
-    if self._deferred:%0A        return original_Model__reduce__(self)%0A    else:%0A    
     
@@ -558,16 +558,25 @@
 class__%0A
+    try:%0A
         
@@ -603,17 +603,16 @@
 .copy()%0A
-%0A
         
@@ -663,16 +663,16 @@
 s(cls)%5D%0A
-
         
@@ -715,16 +715,143 @@
 ), data)
+%0A    except KeyError:%0A        # data.pop() raises when some attnames are deferred%0A        return original_Model__reduce__(self)
 %0A%0Aif Mod

Fix Django 1.10