Add support for exclusion constraints (#249)

This commit is contained in:
Hannes Ljungberg
2019-12-10 18:50:28 +01:00
committed by Maksim Kurnikov
parent 58b26fdbd3
commit f5f33b061d
4 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
from typing import Optional, Sequence, Tuple, Union
from django.db.models.constraints import BaseConstraint
from django.db.models.expressions import Combinable
from django.db.models.query_utils import Q
class ExclusionConstraint(BaseConstraint):
expressions: Sequence[Tuple[Union[str, Combinable], str]]
index_type: str
condition: Optional[Q]
def __init__(
self,
*,
name: str,
expressions: Sequence[Tuple[Union[str, Combinable], str]],
condition: Optional[Q] = ...,
index_type: Optional[str] = ...,
): ...

View File

@@ -8,6 +8,7 @@ from .ranges import (
FloatRangeField as FloatRangeField, FloatRangeField as FloatRangeField,
DateRangeField as DateRangeField, DateRangeField as DateRangeField,
DateTimeRangeField as DateTimeRangeField, DateTimeRangeField as DateTimeRangeField,
RangeOperators as RangeOperators,
) )
from .hstore import HStoreField as HStoreField from .hstore import HStoreField as HStoreField
from .citext import ( from .citext import (

View File

@@ -29,3 +29,15 @@ class DateTimeRangeField(RangeField):
class DateRangeField(RangeField): class DateRangeField(RangeField):
def __get__(self, instance, owner) -> DateRange: ... def __get__(self, instance, owner) -> DateRange: ...
class RangeOperators:
EQUAL: str
NOT_EQUAL: str
CONTAINS: str
CONTAINED_BY: str
OVERLAPS: str
FULLY_LT: str
FULLY_GT: str
NOT_LT: str
NOT_GT: str
ADJACENT_TO: str

View File

@@ -96,6 +96,7 @@
import django.contrib.postgres.aggregates.general import django.contrib.postgres.aggregates.general
import django.contrib.postgres.aggregates.mixins import django.contrib.postgres.aggregates.mixins
import django.contrib.postgres.aggregates.statistics import django.contrib.postgres.aggregates.statistics
import django.contrib.postgres.constraints
import django.contrib.postgres.fields import django.contrib.postgres.fields
import django.contrib.postgres.fields.array import django.contrib.postgres.fields.array
import django.contrib.postgres.fields.citext import django.contrib.postgres.fields.citext