Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Django 2.0 compatibility #102

Merged
merged 1 commit into from
Dec 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ matrix:
python: 3.6
- env: TOXENV=py36-django111
python: 3.6
- env: TOXENV=py36-django2
python: 3.6

- env: TOXENV=pypy3-django18
python: pypy3
Expand Down
6 changes: 3 additions & 3 deletions reversion_compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_object_version(self):
return getattr(self.version_record, 'object_version')

def get_related(self):
if getattr(self.field, 'rel', None):
if getattr(self.field, 'related_model', None):
obj = self.get_object_version().object
try:
return getattr(obj, self.field.name, None)
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_many_to_many(self):
return {}, {}, [] # TODO: refactor that

# Get the related model of the current field:
return self.get_many_to_something(ids, self.field.rel.to)
return self.get_many_to_something(ids, self.field.related_model)

def get_many_to_something(self, target_ids, related_model, is_reverse=False):
# get instance of reversion.models.Revision():
Expand Down Expand Up @@ -260,7 +260,7 @@ def __init__(self, field, field_name, obj, version1, version2, is_reversed):
self.obj = obj

# is a related field (ForeignKey, ManyToManyField etc.)
self.is_related = getattr(self.field, 'rel', None) is not None
self.is_related = getattr(self.field, 'related_model', None) is not None
self.is_reversed = is_reversed
if not self.is_related:
self.follow = None
Expand Down
8 changes: 4 additions & 4 deletions reversion_compare_tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __str__(self):
@python_2_unicode_compatible
class Car(models.Model):
name = models.CharField(max_length=128)
manufacturer = models.ForeignKey(Factory, related_name="cars")
manufacturer = models.ForeignKey(Factory, related_name="cars", on_delete=models.CASCADE)
supplier = models.ManyToManyField(Factory, related_name="suppliers", blank=True)

def __str__(self):
Expand All @@ -82,7 +82,7 @@ class Person(models.Model):
name = models.CharField(max_length=100)
pets = models.ManyToManyField(Pet, blank=True)
# If you work someone, its at a build, but maybe not a factory!
workplace = models.ForeignKey(Building, related_name="workers", null=True)
workplace = models.ForeignKey(Building, related_name="workers", null=True, on_delete=models.CASCADE)

def __str__(self):
return self.name
Expand All @@ -91,7 +91,7 @@ def __str__(self):
@python_2_unicode_compatible
class Identity(models.Model):
id_numer = models.CharField(max_length=100)
person = models.OneToOneField(Person, related_name='_identity')
person = models.OneToOneField(Person, related_name='_identity', on_delete=models.CASCADE)

def __str__(self):
return self.id_numer
Expand Down Expand Up @@ -165,7 +165,7 @@ class TemplateField(models.Model):
"""
# some field for easy creating revisions
text = models.CharField(max_length=20)
template = models.ForeignKey(Person, blank=True, null=True)
template = models.ForeignKey(Person, blank=True, null=True, on_delete=models.CASCADE)

"""
@python_2_unicode_compatible
Expand Down
2 changes: 1 addition & 1 deletion reversion_compare_tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
},]

MIDDLEWARE_CLASSES = (
MIDDLEWARE_CLASSES = MIDDLEWARE = (
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down
5 changes: 4 additions & 1 deletion reversion_compare_tests/test_custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
) % err
raise ImportError(msg)

from django.core.urlresolvers import reverse
try:
from django.urls import reverse
except: # Django < 1.10 # pragma: no cover
from django.core.urlresolvers import reverse

from reversion_compare_tests.models import CustomModel
from .utils.test_cases import BaseTestCase
Expand Down
2 changes: 1 addition & 1 deletion reversion_compare_tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/', admin.site.urls),

url(r'^test_view/(?P<pk>\d+)$', SimpleModelHistoryCompareView.as_view() ),

Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[tox]
envlist =
{py35,py36,pypy3}-django{18,111}{-dmp,}
{py35,py36,pypy3}-django{18,111,2}{-dmp,}

[testenv]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
Expand All @@ -21,6 +21,7 @@ basepython =
deps =
django18: Django>=1.8,<1.9
django111: Django>=1.11,<2.0
django2: Django>=2.0,<3.0
dmp: diff-match-patch
-r{toxinidir}/requirements-test.txt

Expand Down