Support Django 2.2 and stop RemovedInDjango30Warning

Taken from:

commit a2bcd795ed68d0b5882e853e731624f572cbb28e
Author: Adam Johnson <me@adamj.eu>
Date:   Sun Apr 28 23:08:54 2019 +0100

    Support Django 2.2 and stop RemovedInDjango30Warning (#13)

    * Add HISTORY note and update README
    * Add 2.2 to tox testing grid
    * Update `classifiers` in `setup.py`

without the related documentation/build changes.
This commit is contained in:
Frédéric Péters 2021-04-09 13:33:04 +02:00 committed by Frederic Peters
parent f63f14d65e
commit c80f49c760
1 changed files with 11 additions and 5 deletions

View File

@ -1,6 +1,7 @@
from __future__ import unicode_literals
import json
import django
from django.core.exceptions import ValidationError
from django.conf import settings
from django.db import models
@ -80,11 +81,16 @@ class JSONField(models.Field):
return 'long'
return 'text'
def from_db_value(self, value, expression, connection, context):
if value is None:
return None
return json.loads(value, **self.decoder_kwargs)
if django.VERSION > (2, 0):
def from_db_value(self, value, expression, connection):
if value is None:
return None
return json.loads(value, **self.decoder_kwargs)
else:
def from_db_value(self, value, expression, connection, context):
if value is None:
return None
return json.loads(value, **self.decoder_kwargs)
def get_db_prep_value(self, value, connection=None, prepared=None):
return self.get_prep_value(value)