diff options
author | Stephen Finucane <stephen.finucane@intel.com> | 2015-12-08 17:03:10 +0000 |
---|---|---|
committer | Stephen Finucane <stephen.finucane@intel.com> | 2016-01-19 21:55:28 +0000 |
commit | 9d4851a8d6f80b03d4f8ae30623fa0f956584a41 (patch) | |
tree | 2d39adf7a42f5f2c5cc058f12e91a3cb42ca24b8 | |
parent | d08883937e4e0e9fa520df6392630c7e3fa16480 (diff) | |
download | patchwork-9d4851a8d6f80b03d4f8ae30623fa0f956584a41.tar patchwork-9d4851a8d6f80b03d4f8ae30623fa0f956584a41.tar.gz |
models: Resolve SubfieldBase deprecation warnings
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@intel.com>
-rw-r--r-- | patchwork/models.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/patchwork/models.py b/patchwork/models.py index b112a36..a237964 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 @@ -178,8 +178,13 @@ class State(models.Model): ordering = ['ordering'] -@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 @@ -205,6 +210,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 |