I have a Django model with a name TimeSpanwith the field start_datetimeand end_datetime, and I want to validate on the model so that the two objects TimeSpando not overlap.
However, if I wrote the code as shown below,
if timespan.is_valid():
timespan.save()
then there may be a race condition in which two objects TimeSpanare considered valid compared to what is currently in the database, and then they are saved, despite the fact that they are not valid together.
I could make a synchronized method validate_and_save()with locks, but that would break the Django admin. Is there an alternative built into Django?
source
share