Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Django update alternate model instances in shell
"""
Update alternate instances of a model in the database.
"""
from app.models import Post
ids_to_update = list(Post.objects.all().values_list('id', flat=True))[1::2]
Post.objects.filter(id__in=ids_to_update).update(some_field='some value')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment