0

My model is like this:

class B(Model):
 parent = ForeignKey(A)
 duration = DateRangeField()
 title = CharField(max_length=200)

 class Meta:
  unique_together = ('parent', 'duration')

The above unique_together, just checks for equality in case of duration. How can I implement unique_together, so that overlapping duration doesn't get inserted into the table for Model B?

How can I make DateRangeField to include upper_bound by default in my app?

Anagh
  • 31
  • 4
  • Perhaps related to https://stackoverflow.com/questions/26735955/postgres-constraint-for-unique-datetime-range#26736759 – meshy Jun 10 '18 at 16:33
  • @meshy thanks, yeah I did add exclusion constraint at DB level. Is there any Django ORM support for such a check? Also, how can I make DateRangeField to include upper_bound by default in my app? – Anagh Jun 10 '18 at 16:42
  • I don't think there's support yet, but it looks like support for custom constraints is getting closer: https://github.com/django/django/pull/7615 – meshy Jun 10 '18 at 16:42

0 Answers0