From 09d4da252d127fc6b817202026c996825459e0ad Mon Sep 17 00:00:00 2001 From: chris-bradley Date: Fri, 6 Oct 2017 11:27:09 -0600 Subject: [PATCH 1/5] Fixed deprecated reference to field.rel with field.remote_field. --- simple_history/models.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/simple_history/models.py b/simple_history/models.py index 8da15d343..9e021ed7c 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -94,8 +94,10 @@ def setup_m2m_history(self, cls): field = getattr(cls, field.name).field assert isinstance(field, models.fields.related.ManyToManyField), \ ('%s must be a ManyToManyField' % field.name) - if not sum([isinstance(item, HistoricalRecords) for item in field.rel.through.__dict__.values()]): - through_model = field.rel.through + if not sum([ + isinstance(item, HistoricalRecords) for item in field.remote_field.through.__dict__.values() + ]): + through_model = field.remote_field.through if through_model._meta.auto_created and not_registered(through_model): through_model.history = HistoricalRecords() register(through_model) @@ -106,8 +108,10 @@ def setup_m2m_history(self, cls): field = getattr(cls, field_name).field assert isinstance(field, models.fields.related.ManyToManyField), \ ('%s must be a ManyToManyField' % field_name) - if not sum([isinstance(item, HistoricalRecords) for item in field.rel.through.__dict__.values()]): - through_model = field.rel.through + if not sum([ + isinstance(item, HistoricalRecords) for item in field.remote_field.through.__dict__.values() + ]): + through_model = field.remote_field.through if through_model._meta.auto_created and not_registered(through_model): through_model.history = HistoricalRecords() register(through_model) @@ -205,7 +209,7 @@ def copy_fields(self, model): try: field.remote_field = copy.copy(field.remote_field) except AttributeError: - field.rel = copy.copy(field.rel) + field.remote_field = copy.copy(field.remote_field) if isinstance(field, OrderWrt): # OrderWrt is a proxy field, switch to a plain IntegerField field.__class__ = models.IntegerField @@ -222,7 +226,7 @@ def copy_fields(self, model): if getattr(old_field, 'db_column', None): field_arguments['db_column'] = old_field.db_column field = FieldType( - old_field.rel.to, + old_field.remote_field.to, related_name='+', null=True, blank=True, @@ -307,7 +311,7 @@ def pre_delete(self, instance, **kwargs): other side of the m2m relationship. """ for m2m_field in instance._meta.many_to_many: - through_model = m2m_field.rel.through + through_model = m2m_field.remote_field.through if hasattr(through_model._meta, 'simple_history_manager_attribute'): items = through_model.objects.filter(Q(**{m2m_field.m2m_column_name(): instance.pk})) for item in items: @@ -322,9 +326,9 @@ def m2m_changed(self, action, instance, sender, **kwargs): source_field_name, target_field_name = None, None for field_name, field_value in sender.__dict__.items(): if isinstance(field_value, ManyToOneDescriptor): - if field_value.field.rel.model == kwargs['model']: + if field_value.field.remote_field.model == kwargs['model']: target_field_name = field_name - elif isinstance(instance, field_value.field.rel.model): + elif isinstance(instance, field_value.field.remote_field.model): source_field_name = field_name items = sender.objects.filter(**{source_field_name: instance}) if kwargs['pk_set']: @@ -402,7 +406,7 @@ def transform_field(field): def has_m2m_field(instance, through): for m2m_field in instance._meta.many_to_many: - if through is m2m_field.rel.through: + if through is m2m_field.remote_field.through: return True return False From 0ddf7cc92a6296a18c940a6d9c744926de504677 Mon Sep 17 00:00:00 2001 From: chris-bradley Date: Fri, 6 Oct 2017 11:27:57 -0600 Subject: [PATCH 2/5] Fixed deprecated import path for reverse(). --- simple_history/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple_history/admin.py b/simple_history/admin.py index a9fcec781..391c01e7c 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -6,7 +6,7 @@ from django.contrib import admin from django.contrib.admin import helpers from django.contrib.contenttypes.models import ContentType -from django.core.urlresolvers import reverse +from django.urls import reverse from django.shortcuts import get_object_or_404, render from django.utils.text import capfirst from django.utils.html import mark_safe From dd44a3a3fda78c379c7cacfb1474aeb5c6eef1df Mon Sep 17 00:00:00 2001 From: chris-bradley Date: Fri, 6 Oct 2017 11:40:22 -0600 Subject: [PATCH 3/5] Replaced deprecated reference to ForeignObjectRel.to with ForeignObjectRel.model. --- simple_history/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple_history/models.py b/simple_history/models.py index 9e021ed7c..34010509a 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -226,7 +226,7 @@ def copy_fields(self, model): if getattr(old_field, 'db_column', None): field_arguments['db_column'] = old_field.db_column field = FieldType( - old_field.remote_field.to, + old_field.remote_field.model, related_name='+', null=True, blank=True, From b8288b5dd72e6d6a48cacc9bd6844643a3f8e84f Mon Sep 17 00:00:00 2001 From: chris-bradley Date: Fri, 6 Oct 2017 11:48:24 -0600 Subject: [PATCH 4/5] Fixed deprecated call to user.is_authenticated(). --- simple_history/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple_history/models.py b/simple_history/models.py index 34010509a..08006897a 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -374,7 +374,7 @@ def get_history_user(self, instance): return instance._history_user except AttributeError: try: - if self.thread.request.user.is_authenticated(): + if self.thread.request.user.is_authenticated: return self.thread.request.user return None except AttributeError: From 6d64eb4b861fbc7f6570a18c78c48ff406e9e475 Mon Sep 17 00:00:00 2001 From: chris-bradley Date: Fri, 6 Oct 2017 12:32:27 -0600 Subject: [PATCH 5/5] Bumped version number to 1.8.2+ebd3 --- simple_history/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple_history/__init__.py b/simple_history/__init__.py index 497b42800..e80c5adae 100755 --- a/simple_history/__init__.py +++ b/simple_history/__init__.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -__version__ = '1.8.2+ebd1' +__version__ = '1.8.2+ebd3' def register(