Skip to content

Commit

Permalink
(feat): add full compatibility with Django 2.x
Browse files Browse the repository at this point in the history
- fix Django 1.10+ deprecation of the Manager's use_for_related_fields
  by replacing with Meta.base_manager_name on the Model
  - add a check for Django < 1.10 so that this maintains backward
    compatibility while not giving warnings for newer versions

- (docs): change docs to note this
- (pub): add Django 2.1 classifier
  • Loading branch information
agilgur5 committed Jul 31, 2018
1 parent 71f5cb8 commit df0e3f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ It is expected that you already have Django installed
_This was originally used in an older Django 1.5 codebase with Python 2.7._

Should work with Django 1.4-1.9 with Python 2.7-3.x.
- Likely works with Django 1.10 and 1.11, though not 100% sure that [`._meta.fields` usage works the same way in these](https://docs.djangoproject.com/en/2.0/ref/models/meta/#migrating-old-meta-api).
- Will have some problems with Django 2.0 as the Manager's [`use_for_related_fields` has been removed](https://docs.djangoproject.com/en/2.0/releases/2.0/#features-removed-in-2-0).
- Likely works with Django 1.10-2.x, though not 100% sure that [`._meta.fields` usage works the same way in these](https://docs.djangoproject.com/en/2.0/ref/models/meta/#migrating-old-meta-api).
- `2to3` shows that there is nothing to change, so should be compatible with Python 3.x
- Likely works with Django 0.95-1.3 as well; pre 0.95, the Manager API didn't exist
- Have not confirmed if this works with earlier versions of Python.
Expand Down
8 changes: 6 additions & 2 deletions serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def serialize(self, *args):

class SerializableManager(models.Manager):
"""Implements table-level serialization via SerializableQuerySet"""
# when queried from a related Model, use this Manager
use_for_related_fields = True
# backward compatibility for Django < 1.10
if django.VERSION < (1, 10):
# when queried from a related Model, use this Manager
use_for_related_fields = True

def get_queryset(self):
return _SerializableQuerySet(self.model)
Expand Down Expand Up @@ -44,6 +46,8 @@ class SerializableModel(models.Model):

class Meta:
abstract = True
# when queried from a related Model, use this Manager
base_manager_name = 'SerializableManager'

def serialize(self, *args, **kwargs):
"""
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
],
keywords=('django serializer serializers serializer-django serialize ' +
'json dict queryset model modelmanager full wadofstuff'),
Expand Down

0 comments on commit df0e3f0

Please sign in to comment.