Hi
I build this model which has two DateTimeRange fields:
class Booking(BaseModel):
class Status(models.TextChoices):
PAID = "Paid", _("Paid")
EXPIRED = "Expired", _("Expired")
PEDNING = "Pending", _("Pending")
ACCEPTED = "Accepted", _("Accepted")
REJECTED = "Rejected", _("Rejected")
CANCELLED = "Cancelled", _("Cancelled")
related_property = models.ForeignKey(
to='Property.Property', on_delete=models.PROTECT, null=False,
verbose_name=_("Property"), related_name="bookings", related_query_name="booking"
)
client = models.ForeignKey(
to='Authentication.Client', on_delete=models.PROTECT, null=False,
verbose_name=_("User"), related_name="reservations", related_query_name="reservation"
)
client_checking_range = DateTimeRangeField(
default_bounds='[]', verbose_name=_("Reservation"), null=True) # to be false
original_reservation = DateTimeRangeField(
default_bounds='[]', verbose_name=_('Original Reservation'), null=True) # to be false
checked_in = models.BooleanField(default=False, null=False, verbose_name=_('Checked In'))
checked_out = models.BooleanField(default=False, null=False, verbose_name=_('Checked Out'))
price = models.PositiveIntegerField(verbose_name=_("Price"), null=False, default=1) # default to be removed
num_of_adults = models.SmallIntegerField(null=False, verbose_name=_("Num of adults"))
num_of_children = models.SmallIntegerField(null=False, verbose_name=_("Num of children"))
status = models.CharField(verbose_name=_("Status"), max_length=16,
choices=Status.choices, default=Status.PEDNING, null=False)
class Meta:
verbose_name = _("Booking")
verbose_name_plural = _("Bookings")
indexes = [
# models.Index(fields=['client_checking_range',]),
GinIndex(
fields=['client_checking_range', ],
name='booking_client_range_gin_idx'
)
# GistIndex(
# fields=('client_checking_range',),
# name='checking_range_gist_idx',
# buffering=True
# ),
# GistIndex(
# OpClass('client_checking_range', name='range_ops'),
# # fields=('client_checking_range', ),
# name='client_checking_range_gist_idx',
# # opclasses=['range_ops'],
# buffering=True
# ),
# GistIndex(
# fields=('original_reservation', ),
# name='original_reservation_gist_idx',
# opclasses=['range_ops'],
# buffering=True
# )
]
constraints = [
ExclusionConstraint(
name="non_overlapped_reservation",
expressions=[
# ("client_checking_range", RangeOperators.OVERLAPS),
(OpClass("client_checking_range", name="range_ops"), RangeOperators.OVERLAPS),
("related_property", RangeOperators.EQUAL)
],
condition=Q(status="Accepted") | Q(status="Paid") | Q(status="Pending"),
)
]
I built the rest api for this model and do some tests on postman, then I try to build unittest for this APIs, and when I call pytest from the terminal, it always show this error message:
E django.db.utils.ProgrammingError: data type bigint has no default operator class for access method “gist”
E HINT: You must specify an operator class for the index or define a default operator class for the data type.
as you can see in the model I try multiple indexing solutions (and others tried but not showed here) but the result still same, so any one can help me with this problem?
thanks very much