From 314f7d4c7786e7fec0846151728f1330eff579d7 Mon Sep 17 00:00:00 2001 From: mikob Date: Fri, 8 Jun 2018 21:45:45 +0900 Subject: [PATCH] Updated to work with Django 2 --- django_hstore/managers.py | 12 ++++++++++-- django_hstore/query.py | 5 ++++- django_hstore/virtual.py | 4 +++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/django_hstore/managers.py b/django_hstore/managers.py index dcfa62e..ca45e35 100644 --- a/django_hstore/managers.py +++ b/django_hstore/managers.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals, absolute_import +import django from django.db import models from django_hstore.query import HStoreQuerySet @@ -28,10 +29,17 @@ def hslice(self, attr, keys, **params): if GEODJANGO_INSTALLED: - from django.contrib.gis.db import models as geo_models + if django.VERSION[0] == 1: + from django.contrib.gis.db.models import GeoManager + class HStoreGeoManagerBase(GeoManager, HStoreManager): + pass + else: + class HStoreGeoManagerBase(HStoreManager): + pass + from django_hstore.query import HStoreGeoQuerySet - class HStoreGeoManager(geo_models.GeoManager, HStoreManager): + class HStoreGeoManager(HStoreGeoManagerBase): """ Object manager combining Geodjango and hstore. """ diff --git a/django_hstore/query.py b/django_hstore/query.py index 74f6372..ff4bc99 100644 --- a/django_hstore/query.py +++ b/django_hstore/query.py @@ -222,7 +222,10 @@ def hupdate(self, query, attr, updates): if GEODJANGO_INSTALLED: - from django.contrib.gis.db.models.query import GeoQuerySet + if django.VERSION[0] == 1: + from django.contrib.gis.db.models.query import GeoQuerySet + else: + GeoQuerySet = QuerySet if django.VERSION[:2] <= (1, 7): from django.contrib.gis.db.models.sql.query import GeoQuery diff --git a/django_hstore/virtual.py b/django_hstore/virtual.py index 9514a77..5469db9 100644 --- a/django_hstore/virtual.py +++ b/django_hstore/virtual.py @@ -30,7 +30,9 @@ def contribute_to_class(self, cls, name): # Connect myself as the descriptor for this field setattr(cls, name, self) # add field to class - if DJANGO_VERSION[:2] >= (1, 8): + if DJANGO_VERSION[0] >= 2: + cls._meta.add_field(self, private=True) + elif DJANGO_VERSION[:2] >= (1, 8): # virtual=True available since django 1.8 cls._meta.add_field(self, virtual=True) else: