Fixed #24604 -- Added JSONField to contrib.postgres.

This commit is contained in:
Marc Tamlyn 2015-05-30 22:13:58 +01:00
parent 74fe4428e5
commit 33ea472f69
11 changed files with 540 additions and 3 deletions

View file

@ -2,7 +2,7 @@ from django.db import connection, models
from .fields import (
ArrayField, BigIntegerRangeField, DateRangeField, DateTimeRangeField,
FloatRangeField, HStoreField, IntegerRangeField,
FloatRangeField, HStoreField, IntegerRangeField, JSONField,
)
@ -52,7 +52,7 @@ class TextFieldModel(models.Model):
field = models.TextField()
# Only create this model for databases which support it
# Only create this model for postgres >= 9.2
if connection.vendor == 'postgresql' and connection.pg_version >= 90200:
class RangesModel(PostgreSQLModel):
ints = IntegerRangeField(blank=True, null=True)
@ -66,6 +66,16 @@ else:
pass
# Only create this model for postgres >= 9.4
if connection.vendor == 'postgresql' and connection.pg_version >= 90400:
class JSONModel(models.Model):
field = JSONField(blank=True, null=True)
else:
# create an object with this name so we don't have failing imports
class JSONModel(object):
pass
class ArrayFieldSubclass(ArrayField):
def __init__(self, *args, **kwargs):
super(ArrayFieldSubclass, self).__init__(models.IntegerField())