mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #24001 -- Added range fields for PostgreSQL.
Added support for PostgreSQL range types to contrib.postgres. - 5 new model fields - 4 new form fields - New validators - Uses psycopg2's range type implementation in python
This commit is contained in:
parent
916e38802f
commit
48ad288679
15 changed files with 986 additions and 6 deletions
|
@ -1,5 +1,8 @@
|
|||
from django.contrib.postgres.fields import ArrayField, HStoreField
|
||||
from django.db import models
|
||||
from django.contrib.postgres.fields import (
|
||||
ArrayField, HStoreField, IntegerRangeField, BigIntegerRangeField,
|
||||
FloatRangeField, DateTimeRangeField, DateRangeField,
|
||||
)
|
||||
from django.db import connection, models
|
||||
|
||||
|
||||
class IntegerArrayModel(models.Model):
|
||||
|
@ -34,6 +37,20 @@ class TextFieldModel(models.Model):
|
|||
field = models.TextField()
|
||||
|
||||
|
||||
# Only create this model for databases which support it
|
||||
if connection.vendor == 'postgresql' and connection.pg_version >= 90200:
|
||||
class RangesModel(models.Model):
|
||||
ints = IntegerRangeField(blank=True, null=True)
|
||||
bigints = BigIntegerRangeField(blank=True, null=True)
|
||||
floats = FloatRangeField(blank=True, null=True)
|
||||
timestamps = DateTimeRangeField(blank=True, null=True)
|
||||
dates = DateRangeField(blank=True, null=True)
|
||||
else:
|
||||
# create an object with this name so we don't have failing imports
|
||||
class RangesModel(object):
|
||||
pass
|
||||
|
||||
|
||||
class ArrayFieldSubclass(ArrayField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ArrayFieldSubclass, self).__init__(models.IntegerField())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue