Delete an object automatically after 5 minutes
问题 I'm trying to create a function that automatically delete an object after 5 minutes from publication. from django.contrib.gis.db import models from django.utils import timezone import datetime class Event(models.Model): name = models.CharField( max_length=100, ) publishing_date = models.DateTimeField( default=timezone.now, blank=True, ) @property def delete_after_five_minutes(self): time = self.publishing_date + datetime.timedelta(minutes=5) if time > datetime.datetime.now(): e = Event