Skip to content

Instantly share code, notes, and snippets.

@morenoh149
Last active February 27, 2020 21:32
Show Gist options
  • Save morenoh149/3dc7d93fd2034f1a42013f3274876aed to your computer and use it in GitHub Desktop.
Save morenoh149/3dc7d93fd2034f1a42013f3274876aed to your computer and use it in GitHub Desktop.
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