2015-04-05 00:10:26 +08:00
|
|
|
"""
|
|
|
|
Indirection layer for PostgreSQL-specific fields, so the tests don't fail when
|
|
|
|
run with a backend other than PostgreSQL.
|
|
|
|
"""
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
try:
|
|
|
|
from django.contrib.postgres.fields import (
|
2016-06-02 05:43:59 +08:00
|
|
|
ArrayField, BigIntegerRangeField, CITextField, DateRangeField,
|
|
|
|
DateTimeRangeField, FloatRangeField, HStoreField, IntegerRangeField,
|
|
|
|
JSONField,
|
2015-04-05 00:10:26 +08:00
|
|
|
)
|
2015-06-01 05:45:03 +08:00
|
|
|
from django.contrib.postgres.search import SearchVectorField
|
2015-04-05 00:10:26 +08:00
|
|
|
except ImportError:
|
|
|
|
class DummyArrayField(models.Field):
|
|
|
|
def __init__(self, base_field, size=None, **kwargs):
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(**kwargs)
|
2015-04-05 00:10:26 +08:00
|
|
|
|
|
|
|
def deconstruct(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
name, path, args, kwargs = super().deconstruct()
|
2015-04-05 00:10:26 +08:00
|
|
|
kwargs.update({
|
|
|
|
'base_field': '',
|
|
|
|
'size': 1,
|
|
|
|
})
|
|
|
|
return name, path, args, kwargs
|
|
|
|
|
2016-08-12 03:05:52 +08:00
|
|
|
class DummyJSONField(models.Field):
|
|
|
|
def __init__(self, encoder=None, **kwargs):
|
2017-01-21 21:13:44 +08:00
|
|
|
super().__init__(**kwargs)
|
2016-08-12 03:05:52 +08:00
|
|
|
|
2015-04-05 00:10:26 +08:00
|
|
|
ArrayField = DummyArrayField
|
|
|
|
BigIntegerRangeField = models.Field
|
2016-06-02 05:43:59 +08:00
|
|
|
CITextField = models.Field
|
2015-04-05 00:10:26 +08:00
|
|
|
DateRangeField = models.Field
|
|
|
|
DateTimeRangeField = models.Field
|
|
|
|
FloatRangeField = models.Field
|
|
|
|
HStoreField = models.Field
|
|
|
|
IntegerRangeField = models.Field
|
2016-08-12 03:05:52 +08:00
|
|
|
JSONField = DummyJSONField
|
2015-06-01 05:45:03 +08:00
|
|
|
SearchVectorField = models.Field
|