[Answered ]-Can this be done with the ORM? – Django

2👍

It’s not much work to do it manually:

from django.db import connection

items = Item.objects.filter(created_on__gte=datetime.now()-timedelta(days=7))
cursor = connection.cursor()
cursor.executemany("UPDATE myapp_item SET reddit_rank = %s WHERE id = %s",
                   [(reddit_rank(item), item.pk) for item in items])
cursor.close()

Leave a comment