-
Notifications
You must be signed in to change notification settings - Fork 329
Closed as not planned
Closed as not planned
Copy link
Labels
enhancementNew feature or requestNew feature or request
Description
Suggestion:
Wouldn't it be nice to add support for the field DateTimeRangeField from Postgres as this field is used a lot.
Screenshot
Code
from django.contrib.postgres.constraints import ExclusionConstraint
from django.contrib.postgres.fields import DateTimeRangeField, RangeOperators
from django.db import models
from django.db.models import Q
class Event(models.Model):
title = models.CharField(max_length=200)
timespan = DateTimeRangeField(null=True)
capacity = models.PositiveIntegerField()
cancelled = models.BooleanField(default=False)
class Meta:
constraints = [
ExclusionConstraint(
name="prevent_overlapping_events",
expressions=[
("timespan", RangeOperators.OVERLAPS),
],
condition=Q(cancelled=False),
),
models.CheckConstraint(
check=Q(capacity__gte=1),
name="capacity_gte_1"
),
]
Documentation URL
https://docs.djangoproject.com/en/5.1/ref/contrib/postgres/fields/#daterangefield
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request