This is a digital library system. When borrow end_date has expired, borrow status will be updated automatically to 1 (End), table book column stock will be updated adding one stock, and automatically inserting new content value in table notification.
class Borrow(models.Model):
status = models.CharField(max_length=1, choices=[('0', 'Process'),('1', 'End')], default=0)
book = models.ForeignKey('models.Book', on_delete=models.CASCADE, related_name='borrow_book')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
end_date = models.DateTimeField()
class Book(models.Model):
stock = models.IntegerField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Notification(models.Model):
content = models.CharField(max_length=255, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
How to make an automatic update query in table borrow column status, table book column stock, and insert in table notification when end_date > DateTime.now() ?