1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Prevent DateRangeField overlap in Django model?

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 19:42.

  1. Stack

    Stack Membro Participativo

    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


    class Booking(models.model):
    # The resource to be reserved
    resource = models.ForeignKey('Resource')
    # When to reserve the resource
    date_range = models.DateRangeField()

    class Meta:
    unique_together = ('resource', 'date_range',)

    Continue reading...

Compartilhe esta Página