Last active
February 27, 2020 21:32
-
-
Save morenoh149/3dc7d93fd2034f1a42013f3274876aed to your computer and use it in GitHub Desktop.
Django update alternate model instances in shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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