Skip to content

Commit df0e3f0

Browse files
committed
(feat): add full compatibility with Django 2.x
- 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
1 parent 71f5cb8 commit df0e3f0

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ It is expected that you already have Django installed
2727
_This was originally used in an older Django 1.5 codebase with Python 2.7._
2828

2929
Should work with Django 1.4-1.9 with Python 2.7-3.x.
30-
- 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).
31-
- 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).
30+
- 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).
3231
- `2to3` shows that there is nothing to change, so should be compatible with Python 3.x
3332
- Likely works with Django 0.95-1.3 as well; pre 0.95, the Manager API didn't exist
3433
- Have not confirmed if this works with earlier versions of Python.

serializable.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ def serialize(self, *args):
1414

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

2022
def get_queryset(self):
2123
return _SerializableQuerySet(self.model)
@@ -44,6 +46,8 @@ class SerializableModel(models.Model):
4446

4547
class Meta:
4648
abstract = True
49+
# when queried from a related Model, use this Manager
50+
base_manager_name = 'SerializableManager'
4751

4852
def serialize(self, *args, **kwargs):
4953
"""

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'Framework :: Django :: 1.10',
4444
'Framework :: Django :: 1.11',
4545
'Framework :: Django :: 2.0',
46+
'Framework :: Django :: 2.1',
4647
],
4748
keywords=('django serializer serializers serializer-django serialize ' +
4849
'json dict queryset model modelmanager full wadofstuff'),

0 commit comments

Comments
 (0)