diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ade1959..66cbe8e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,13 @@ -Version 1.1.0 (UNRELEASED) +Version 1.1.0 (UNRELEASED) - HAS BREAKING CHANGES =========================================================== * Switched to testing with PostgreSQL +* Switch to using native JSONField on Django>=1.9. If you + are upgrading an existing installation you will need to + execute the following SQL command manually: + `ALTER TABLE "papertrail_entry" ALTER COLUMN "data" TYPE jsonb USING "data"::jsonb;` + This is because there is no easy way to change the + underlying field AND dropping the dependency on django-jsonfield + at the same time. Sorry :( Version 1.0.5 (2016-06-22) diff --git a/papertrail/__init__.py b/papertrail/__init__.py index e5d2603..35f13af 100644 --- a/papertrail/__init__.py +++ b/papertrail/__init__.py @@ -1,2 +1,2 @@ -__version__ = '1.0.5' +__version__ = '1.1.0' default_app_config = 'papertrail.apps.PapertrailConfig' diff --git a/papertrail/fields.py b/papertrail/fields.py new file mode 100644 index 0000000..7d57998 --- /dev/null +++ b/papertrail/fields.py @@ -0,0 +1,9 @@ +# Attempt to use the built-in PostgreSQL json field, but if that is not +# available try the 3rd party jsonfield one. +try: + from django.contrib.postgres.fields import JSONField as BaseJSONField +except: + from jsonfield.fields import JSONField as BaseJSONField + +class JSONField(BaseJSONField): + pass diff --git a/papertrail/migrations/0001_initial.py b/papertrail/migrations/0001_initial.py index 80c92fe..2aeff29 100644 --- a/papertrail/migrations/0001_initial.py +++ b/papertrail/migrations/0001_initial.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -import jsonfield.fields +import papertrail.fields from django.db import migrations, models @@ -19,7 +19,7 @@ class Migration(migrations.Migration): ('timestamp', models.DateTimeField(db_index=True)), ('type', models.CharField(max_length=50, db_index=True)), ('message', models.CharField(max_length=512)), - ('data', jsonfield.fields.JSONField(null=True)), + ('data', papertrail.fields.JSONField(null=True)), ('external_key', models.CharField(max_length=255, null=True, db_index=True)), ], options={ diff --git a/papertrail/models.py b/papertrail/models.py index 865744c..e9c7ceb 100644 --- a/papertrail/models.py +++ b/papertrail/models.py @@ -2,7 +2,6 @@ import logging -import jsonfield.fields from django.conf import settings from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType @@ -10,6 +9,7 @@ from django.utils import timezone from papertrail import signals +from papertrail.fields import JSONField LOG = logging.getLogger(__name__) @@ -202,7 +202,7 @@ class Entry(models.Model, ModelWithRelatedObjectsMixin): timestamp = models.DateTimeField(db_index=True) type = models.CharField(max_length=50, db_index=True) message = models.CharField(max_length=512) - data = jsonfield.fields.JSONField(null=True) + data = JSONField(null=True) # Field for storing a custom 'key' for looking up specific events from # external sources. This can be used to quickly and precisely look up diff --git a/papertrail/requirements.txt b/papertrail/requirements.txt index 016b7dc..a2e6378 100644 --- a/papertrail/requirements.txt +++ b/papertrail/requirements.txt @@ -1,3 +1,2 @@ -django-jsonfield>=0.8.11 django-apptemplates>=1.0 six diff --git a/papertrail/tests.py b/papertrail/tests.py index ccfb191..b0e1fec 100644 --- a/papertrail/tests.py +++ b/papertrail/tests.py @@ -1,10 +1,11 @@ +import unittest +from django import VERSION as django_version from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.contrib.contenttypes.models import ContentType from django.dispatch import receiver from django.test import TestCase from django.utils import timezone - from papertrail import log, signals from papertrail.models import Entry, related_to_q, replace_object_in_papertrail @@ -158,3 +159,13 @@ def test_objects_represented(self): Entry.objects.filter(type='test-entry').objects_not_represented(all_users, 'user').get(), user3 ) + + @unittest.skipIf(django_version < (1, 9), 'no native JSONField') + def test_json_field_filtering(self): + log('test', 'test', data={ + 'field': 'value', + }) + + self.assertTrue( + Entry.objects.filter(data__field='value').exists() + ) diff --git a/setup.py b/setup.py index b1ebbfd..7fc60e2 100644 --- a/setup.py +++ b/setup.py @@ -9,11 +9,10 @@ setup( name='django-papertrail', - version='1.0.5', + version='1.1.0', packages=['papertrail'], install_requires=[ 'Django>=1.7', - 'django-jsonfield>=0.8.11', 'six', 'django-apptemplates', ], diff --git a/tox.ini b/tox.ini index 340355f..6829440 100644 --- a/tox.ini +++ b/tox.ini @@ -14,9 +14,7 @@ basepython = commands = make test deps = psycopg2 - django14: Django>=1.4,<1.5 - django15: Django>=1.5,<1.6 - django16: Django>=1.6,<1.7 + django-jsonfield django17: Django>=1.7,<1.8 django18: Django>=1.8,<1.9 django19: Django>=1.9,<1.10