I have a gallery model in my models.py. I want to automatically move the data to another table called as Archive if created date is more than 30 days.
This is my models.py
class Gallery(models.Model):
id= models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
image = models.ImageField(upload_to='images/')
video = models.FileField(upload_to='videos/', validators=[FileExtensionValidator( ['mp4', 'mov', 'mkv'] )])
tag = models.CharField(max_length=100)
classes = models.ForeignKey(Classes, null=True, blank=True, on_delete=models.CASCADE)
level = models.ForeignKey(Level, null=True, blank=True, on_delete=models.CASCADE)
uploded_date = models.DateTimeField(auto_now_add=True)
class Archive(models.Model):
id= models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
image = models.ImageField(upload_to='images/')
video = models.FileField(upload_to='videos/', validators=[FileExtensionValidator( ['mp4', 'mov', 'mkv'] )])
tag = models.CharField(max_length=100)
classes = models.ForeignKey(Classes, null=True, blank=True, on_delete=models.CASCADE)
level = models.ForeignKey(Level, null=True, blank=True, on_delete=models.CASCADE)
uploded_date = models.DateTimeField(auto_now_add=True)
I have thought of creating signals and sending signals to Archive like this. I have already defined the signal.
def date_is_old(self):
if self.uploded_date > (datetime.datetime.now()-timedelta(days=15)):
date_is_old.send(self.__class__)
But this method seems to be ineffective as it only sends signal at time of creation of new record. I need the function to always check and If creation is past 30 days automatically move data to Archive. Is there some way to handle this? I am really out of option tried modifying create method and save methods on table "Gallery".