From: Stephen Finucane Date: Tue, 8 Dec 2015 17:03:10 +0000 (+0000) Subject: models: Resolve SubfieldBase deprecation warnings X-Git-Tag: v1.1.0~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d4851a8d6f80b03d4f8ae30623fa0f956584a41;p=thirdparty%2Fpatchwork.git 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 --- diff --git a/patchwork/models.py b/patchwork/models.py index b112a36c..a237964a 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