Does anyone know the quickest way to delete any entries from a database that is older then 6 months. So far Ive been using...
Example.objects.filter(date_created__lte="2011-2-9 12:00:00" ).delete()
Thanks,
Try this:
from datetime import datetime, timedelta
Example.objects.filter(date_created__lte=datetime.utcnow() -
timedelta(days=6*30)).delete()
try this if your date_created is of type datetimefield
from datetime import datetime, timedelta
six_months = datetime.now() - timedelta(weeks=24)
Example.objects.filter(date_created__lte=six_months).delete()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.