From 698044bf21e9504e30af423072ae8d0e3b17b12a Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 14:46:19 -0300 Subject: [PATCH 1/7] Update Django to 2.x --- field_history/json_nested_serializer.py | 2 +- field_history/models.py | 4 ++-- field_history/tracker.py | 2 +- runtests.py | 3 ++- tests/models.py | 4 ++-- tests/tests.py | 7 ++++--- tests/urls.py | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/field_history/json_nested_serializer.py b/field_history/json_nested_serializer.py index 35067df..e2d40d4 100644 --- a/field_history/json_nested_serializer.py +++ b/field_history/json_nested_serializer.py @@ -48,7 +48,7 @@ def serialize(self, queryset, **options): # only one change local_fields -> fields for supporting nested models for field in concrete_model._meta.fields: if field.serialize: - if field.rel is None: + if field.remote_field is None: if self.selected_fields is None or field.attname in self.selected_fields: self.handle_field(obj, field) else: diff --git a/field_history/models.py b/field_history/models.py index 6ee4b1d..4bbc9fa 100644 --- a/field_history/models.py +++ b/field_history/models.py @@ -38,12 +38,12 @@ def instantiate_object_id_field(object_id_class_or_tuple=models.TextField): @python_2_unicode_compatible class FieldHistory(models.Model): object_id = instantiate_object_id_field(getattr(settings, OBJECT_ID_TYPE_SETTING, models.TextField)) - content_type = models.ForeignKey('contenttypes.ContentType', db_index=True) + content_type = models.ForeignKey('contenttypes.ContentType', db_index=True, on_delete=models.CASCADE) object = GenericForeignKey() field_name = models.CharField(max_length=500, db_index=True) serialized_data = models.TextField() date_created = models.DateTimeField(auto_now_add=True, db_index=True) - user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True) + user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.CASCADE) objects = FieldHistoryManager() diff --git a/field_history/tracker.py b/field_history/tracker.py index b132a27..972788a 100644 --- a/field_history/tracker.py +++ b/field_history/tracker.py @@ -124,7 +124,7 @@ def get_field_history_user(self, instance): return instance._field_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: diff --git a/runtests.py b/runtests.py index c8e3333..08d91cc 100644 --- a/runtests.py +++ b/runtests.py @@ -14,6 +14,7 @@ }, ROOT_URLCONF="tests.urls", INSTALLED_APPS=[ + "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", @@ -22,7 +23,7 @@ "tests", ], SITE_ID=1, - MIDDLEWARE_CLASSES=( + MIDDLEWARE=( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', diff --git a/tests/models.py b/tests/models.py index 490fa28..e81ed27 100644 --- a/tests/models.py +++ b/tests/models.py @@ -10,7 +10,7 @@ class Pet(models.Model): class Person(models.Model): name = models.CharField(max_length=255) - created_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True) + created_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE) field_history = FieldHistoryTracker(['name']) @@ -20,7 +20,7 @@ def _field_history_user(self): class Owner(Person): - pet = models.ForeignKey(Pet, blank=True, null=True) + pet = models.ForeignKey(Pet, blank=True, null=True, on_delete=models.CASCADE) field_history = FieldHistoryTracker(['name', 'pet']) diff --git a/tests/tests.py b/tests/tests.py index 8b68b16..ddac147 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,10 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import datetime +from decimal import Decimal from django.contrib.auth import get_user_model from django.core.management import CommandError, call_command -from django.core.urlresolvers import reverse +from django.urls import reverse from django.db import models from django.test.utils import override_settings from django.test import TestCase @@ -182,14 +183,14 @@ def test_field_history_works_with_integer_field(self): self.assertIsNotNone(history.date_created) def test_field_history_works_with_decimal_field(self): - human = Human.objects.create(body_temp=98.6) + human = Human.objects.create(body_temp=Decimal(98.6)) self.assertEqual(human.get_body_temp_history().count(), 1) history = human.get_body_temp_history()[0] self.assertEqual(history.object, human) self.assertEqual(history.field_name, 'body_temp') - self.assertEqual(history.field_value, 98.6) + self.assertEqual(history.field_value, Decimal(98.6)) self.assertIsNotNone(history.date_created) def test_field_history_works_with_boolean_field(self): diff --git a/tests/urls.py b/tests/urls.py index 45c4c60..a9201a4 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import include, url +from django.conf.urls import url from django.contrib import admin from . import views @@ -6,5 +6,5 @@ urlpatterns = [ url(r"^$", views.test_view, name="index"), - url(r"^admin/", include(admin.site.urls)), + url(r"^admin/", admin.site.urls), ] From b187724459aac8744eb48339373ba3eb288ac71e Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 14:48:33 -0300 Subject: [PATCH 2/7] Drop support for older Django versions --- .travis.yml | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f84599..b13fb8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,25 +19,9 @@ install: script: make test env: - - DJANGO=1.7.11 - - DJANGO=1.8.17 - - DJANGO=1.9.12 - - DJANGO=1.10.4 - -matrix: - exclude: - - python: 3.2 - env: DJANGO=1.10.4 - - python: 3.3 - env: DJANGO=1.10.4 - - python: 3.2 - env: DJANGO=1.9.12 - - python: 3.3 - env: DJANGO=1.9.12 - - python: 3.5 - env: DJANGO=1.7.11 - - python: 3.6 - env: DJANGO=1.7.11 + - DJANGO=1.11.15 + - DJANGO=2.0.8 + - DJANGO=2.1 after_success: - coveralls From cc0b74b311b058ceb234a8ad886504f32f6e5fe1 Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 14:48:56 -0300 Subject: [PATCH 3/7] Add support for Python 3.7 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b13fb8a..d8cfa7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: - 3.4 - 3.5 - 3.6 + - 3.7 before_install: - pip install coveralls From 504cbfc0480f4fdf0e64e8c1a8d8ad52c384953b Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 14:54:11 -0300 Subject: [PATCH 4/7] Remove unsupported Python versions --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8cfa7c..e04949b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: python python: - 2.7 - - 3.2 - - 3.3 - 3.4 - 3.5 - 3.6 From f5eb507188a3c84b66a51bfafdbc17e67ba6f22a Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 15:03:44 -0300 Subject: [PATCH 5/7] Update documentation --- AUTHORS.rst | 1 + HISTORY.rst | 4 ++++ README.rst | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 4a772f6..a62737a 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -11,6 +11,7 @@ Contributors ------------ * Boris Shifrin +* Matheus Cansian Background ---------- diff --git a/HISTORY.rst b/HISTORY.rst index 6955e7d..bd6a0f4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,10 @@ History 0.6.1 (Not released) ++++++++++++++++++++ * Fixed generic primary key bug with `createinitialfieldhistory` command (#20) +* Dropped support for Python 3.2 and 3.3 +* Dropped support for Django 1.7 through 1.10 +* Added support for Python 3.7 +* Added support for Django 2.1 0.6.0 (December 22, 2016) +++++++++++++++++++++++++ diff --git a/README.rst b/README.rst index 003c589..d12aab4 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,7 @@ django-field-history .. image:: https://coveralls.io/repos/github/grantmcconnaughey/django-field-history/badge.svg?branch=master :target: https://coveralls.io/github/grantmcconnaughey/django-field-history?branch=master -A Django app to track changes to a model field. For Python 2.7/3.2+ and Django 1.7+. +A Django app to track changes to a model field. For Python 2.7/3.4+ and Django 1.11/2.0+. Other similar apps are `django-reversion `_ and `django-simple-history `_, which track *all* model fields. @@ -173,7 +173,7 @@ You will need to also update the ``field_name`` value in all ``FieldHistory`` ob Storing Which User Changed the Field ------------------------------------ -There are two ways to store the user that changed your model field. The simplest way is to use **the logged in user** that made the request. To do this, add the ``FieldHistoryMiddleware`` class to your ``MIDDLEWARE`` setting (in Django 1.10+) or your ``MIDDLEWARE_CLASSES`` setting (in Django 1.7-1.9). +There are two ways to store the user that changed your model field. The simplest way is to use **the logged in user** that made the request. To do this, add the ``FieldHistoryMiddleware`` class to your ``MIDDLEWARE`` setting. .. code-block:: python From d72bd9276124cc2b758864e153181203938508c0 Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 15:07:57 -0300 Subject: [PATCH 6/7] Update travis Python to 3.7-dev Unfortunately Python 3.7 stable is still not realesed on TravisCI https://github.com/travis-ci/travis-ci/issues/9815 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e04949b..8014e1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: - 3.4 - 3.5 - 3.6 - - 3.7 + - 3.7-dev before_install: - pip install coveralls From 38c78f571fc38de540b49d4ebbb37a2663a47fcc Mon Sep 17 00:00:00 2001 From: Matheus Cansian Date: Mon, 27 Aug 2018 15:14:30 -0300 Subject: [PATCH 7/7] Set travis exclusion matrix --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8014e1e..aa8568c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,5 +22,16 @@ env: - DJANGO=2.0.8 - DJANGO=2.1 +matrix: + exclude: + - python: 2.7 + env: DJANGO=2.0.8 + - python: 2.7 + env: DJANGO=2.1 + - python: 3.4 + env: DJANGO=2.1 + - python: 3.7-dev + env: DJANGO=1.11.15 + after_success: - coveralls