Test model
class Room(models.Model):
"""
This stores details of rooms available
"""
name = models.CharField(
null=False,
blank=False,
max_length=100,
help_text='Enter the name of the room'
)
capacity = models.PositiveIntegerField(
null=False,
blank=False,
help_text='Enter the number of person\'s the room can accommodate'
)
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
I want to update the model if it exists and its modified_at time is less than say x time otherwise just create the model. For reference here it the raw sql I want django to execute.
INSERT INTO room VALUES (1,'2018-04-30 18:15:32.96468+04:30','2018-04-30 18:15:32.96468+04:30','Room-A',30) ON CONFLICT(id) DO UPDATE SET capacity=10 WHERE room.modified_at < '2017-04-30 18:15:32.96468+04:30';
Also I would like to know if the SQL query I'have written is atomic or not