Skip to content
Advertisement

Prevent DateRangeField overlap in Django model?

Now that Django supports the DateRangeField, is there a ‘Pythonic’ way to prevent records from having overlapping date ranges?

Hypothetical use case

One hypothetical use case would be a booking system, where you don’t want people to book the same resource at the same time.

Hypothetical example code

JavaScript

Advertisement

Answer

I know that the answer is old, but now you can just create a constraint in the meta of the model, that will make Postgres handle this

JavaScript

Postgress Coonstraints

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement