Here I am writing a middleware to delete objects older than 3 months. The date_before_2_month
and datetime_before_2_months
is working fine. I haven't tested yet for filtering But in my console it is giving me a runtime warning saying activity_time
received a naive datetime.
Is this warning a issue(needs to solve) or we can ignore it ?
Also does my filter parameters are good for querying the objects from model which are 2 months old ?
activity_time
in model is DateTimeField(auto_now_add=True)
class UserActivityLogDeleteMiddleware(object): # middleware for deleting user activity logs which are older than 2 months
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
date_before_2_month = datetime.date.today() - relativedelta(months=2)
# converting into datetime
datetime_before_2_month = datetime.datetime.combine(date_before_2_month, datetime.time(9, 00, 00))
# deleting logs older than 2 months
UserActivityLog.objects.filter(activity_time__lt=datetime_before_2_month).delete()
response = self.get_response(request)
return response