Skip to content

Commit

Permalink
Merge branch 'r1.8.2+ebd3'
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-bradley committed Oct 6, 2017
2 parents a0937ae + 6d64eb4 commit 867615d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion simple_history/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import unicode_literals

__version__ = '1.8.2+ebd1'
__version__ = '1.8.2+ebd3'


def register(
Expand Down
2 changes: 1 addition & 1 deletion simple_history/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions simple_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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.model,
related_name='+',
null=True,
blank=True,
Expand Down Expand Up @@ -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:
Expand All @@ -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']:
Expand Down Expand Up @@ -370,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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 867615d

Please sign in to comment.