Skip to content

Instantly share code, notes, and snippets.

@goltsevnet
Created February 18, 2023 10:30
Show Gist options
  • Select an option

  • Save goltsevnet/6a5e4a123af255f9e1e3f16044bd699b to your computer and use it in GitHub Desktop.

Select an option

Save goltsevnet/6a5e4a123af255f9e1e3f16044bd699b to your computer and use it in GitHub Desktop.
from django.db import migrations
from main_app.models import Book
def change_author(apps, schema_editor):
Book.objects \
.filter(authors__first_name=['Аркадий', 'Борис'], authors__last_name=['Стругацкий']) \
.update('Суахили')
class Migration(migrations.Migration):
dependencies = [
('main_app', '...prepend_migrations...'),
]
operations = [
migrations.RunPython(change_author, reverse_code=migrations.RunPython.noop),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment