Commit d2760238 authored by Brian May's avatar Brian May

Apply updates for version 3.0.0-1

parent 2547d28c
django-model-utils (3.0.0-1) UNRELEASED; urgency=medium
* New upstream version. Closes: :#865559.
-- Brian May <bam@debian.org> Mon, 03 Jul 2017 08:16:26 +1000
django-model-utils (2.5.2-2) unstable; urgency=medium
[ Ben Finney ]
......
From 777393fbb8b0684d2a5fe1095c4ff98965eb1238 Mon Sep 17 00:00:00 2001
From: Brian May <bam@debian.org>
Date: Sun, 11 Sep 2016 12:21:37 +1000
Subject: Fix FieldTracker failing with Django 1.10
From upstream pull request
https://github.com/carljm/django-model-utils/issues/232
---
model_utils/tracker.py | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/model_utils/tracker.py b/model_utils/tracker.py
index a9c7f70..6aa7d8a 100644
--- a/model_utils/tracker.py
+++ b/model_utils/tracker.py
@@ -2,8 +2,9 @@ from __future__ import unicode_literals
from copy import deepcopy
-from django.db import models
+import django
from django.core.exceptions import FieldError
+from django.db import models
from django.db.models.query_utils import DeferredAttribute
@@ -62,12 +63,14 @@ class FieldInstanceTracker(object):
)
def init_deferred_fields(self):
- self.instance._deferred_fields = []
+ self.instance._deferred_fields = set()
if hasattr(self.instance, '_deferred') and not self.instance._deferred:
return
class DeferredAttributeTracker(DeferredAttribute):
def __get__(field, instance, owner):
+ if instance is None:
+ return field
data = instance.__dict__
if data.get(field.field_name, field) is field:
instance._deferred_fields.remove(field.field_name)
@@ -76,19 +79,31 @@ class FieldInstanceTracker(object):
self.saved_data[field.field_name] = deepcopy(value)
return data[field.field_name]
- for field in self.fields:
- field_obj = self.instance.__class__.__dict__.get(field)
- if isinstance(field_obj, DeferredAttribute):
- self.instance._deferred_fields.append(field)
-
- # Django 1.4
- model = None
- if hasattr(field_obj, 'model_ref'):
- model = field_obj.model_ref()
-
+ if django.VERSION >= (1, 8):
+ self.instance._deferred_fields = self.instance.get_deferred_fields()
+ for field in self.instance._deferred_fields:
+ if django.VERSION >= (1, 10):
+ field_obj = getattr(self.instance.__class__, field)
+ else:
+ field_obj = self.instance.__class__.__dict__.get(field)
field_tracker = DeferredAttributeTracker(
- field_obj.field_name, model)
+ field_obj.field_name, None)
setattr(self.instance.__class__, field, field_tracker)
+ else:
+ for field in self.fields:
+ field_obj = self.instance.__class__.__dict__.get(field)
+ if isinstance(field_obj, DeferredAttribute):
+ self.instance._deferred_fields.add(field)
+
+ # Django 1.4
+ if django.VERSION >= (1, 5):
+ model = None
+ else:
+ model = field_obj.model_ref()
+
+ field_tracker = DeferredAttributeTracker(
+ field_obj.field_name, model)
+ setattr(self.instance.__class__, field, field_tracker)
class FieldTracker(object):
0001-Fix-FieldTracker-failing-with-Django-1.10.patch
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment