2015-04-04 16:10:26 +00:00
|
|
|
"""
|
|
|
|
Indirection layer for PostgreSQL-specific fields, so the tests don't fail when
|
|
|
|
run with a backend other than PostgreSQL.
|
|
|
|
"""
|
2019-02-03 23:27:19 +00:00
|
|
|
import enum
|
|
|
|
|
2015-04-04 16:10:26 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
try:
|
|
|
|
from django.contrib.postgres.fields import (
|
2017-02-11 12:16:35 +00:00
|
|
|
ArrayField, BigIntegerRangeField, CICharField, CIEmailField,
|
2018-10-02 23:17:23 +00:00
|
|
|
CITextField, DateRangeField, DateTimeRangeField, DecimalRangeField,
|
2019-06-09 00:56:37 +00:00
|
|
|
HStoreField, IntegerRangeField,
|
2015-04-04 16:10:26 +00:00
|
|
|
)
|
2015-05-31 21:45:03 +00:00
|
|
|
from django.contrib.postgres.search import SearchVectorField
|
2015-04-04 16:10:26 +00:00
|
|
|
except ImportError:
|
|
|
|
class DummyArrayField(models.Field):
|
|
|
|
def __init__(self, base_field, size=None, **kwargs):
|
2017-01-21 13:13:44 +00:00
|
|
|
super().__init__(**kwargs)
|
2015-04-04 16:10:26 +00:00
|
|
|
|
|
|
|
def deconstruct(self):
|
2017-01-21 13:13:44 +00:00
|
|
|
name, path, args, kwargs = super().deconstruct()
|
2015-04-04 16:10:26 +00:00
|
|
|
kwargs.update({
|
|
|
|
'base_field': '',
|
|
|
|
'size': 1,
|
|
|
|
})
|
|
|
|
return name, path, args, kwargs
|
|
|
|
|
|
|
|
ArrayField = DummyArrayField
|
|
|
|
BigIntegerRangeField = models.Field
|
2017-02-11 12:16:35 +00:00
|
|
|
CICharField = models.Field
|
|
|
|
CIEmailField = models.Field
|
2016-06-01 21:43:59 +00:00
|
|
|
CITextField = models.Field
|
2015-04-04 16:10:26 +00:00
|
|
|
DateRangeField = models.Field
|
|
|
|
DateTimeRangeField = models.Field
|
2018-10-02 23:17:23 +00:00
|
|
|
DecimalRangeField = models.Field
|
2015-04-04 16:10:26 +00:00
|
|
|
HStoreField = models.Field
|
|
|
|
IntegerRangeField = models.Field
|
2015-05-31 21:45:03 +00:00
|
|
|
SearchVectorField = models.Field
|
2019-02-03 23:27:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EnumField(models.CharField):
|
|
|
|
def get_prep_value(self, value):
|
|
|
|
return value.value if isinstance(value, enum.Enum) else value
|