[PATCH 10/10] models: Resolve SubfieldBase deprecation warnings
Stephen Finucane
stephen.finucane at intel.com
Mon Jan 11 10:07:59 AEDT 2016
SubfieldBase has been deprecated. It is necessary to add a
'from_db_value' function in place of this mixin.
https://docs.djangoproject.com/en/1.9/releases/1.8/#subfieldbase
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/models.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/patchwork/models.py b/patchwork/models.py
index acec72e..3218920 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -25,6 +25,7 @@ import datetime
import random
import re
+import django
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.sites.models import Site
@@ -34,7 +35,6 @@ from django.db.models import Q
from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property
from django.utils import six
-from django.utils.six import add_metaclass
from django.utils.six.moves import filter
from patchwork.parser import extract_tags, hash_patch
@@ -163,8 +163,13 @@ class State(models.Model):
ordering = ['ordering']
- at add_metaclass(models.SubfieldBase)
-class HashField(models.CharField):
+if django.VERSION < (1, 8):
+ HashFieldBase = six.with_metaclass(models.SubfieldBase, models.CharField)
+else:
+ HashFieldBase = models.CharField
+
+
+class HashField(HashFieldBase):
def __init__(self, algorithm='sha1', *args, **kwargs):
self.algorithm = algorithm
@@ -190,6 +195,9 @@ class HashField(models.CharField):
kwargs['max_length'] = self.n_bytes
super(HashField, self).__init__(*args, **kwargs)
+ def from_db_value(self, value, expression, connection, context):
+ return self.to_python(value)
+
def db_type(self, connection=None):
return 'char(%d)' % self.n_bytes
--
2.0.0
More information about the Patchwork
mailing list