Skip to content

Instantly share code, notes, and snippets.

@yosephbernandus
Last active November 27, 2021 09:07
Show Gist options
  • Select an option

  • Save yosephbernandus/dd5c80eb20e6feff35c7dd80839d047e to your computer and use it in GitHub Desktop.

Select an option

Save yosephbernandus/dd5c80eb20e6feff35c7dd80839d047e to your computer and use it in GitHub Desktop.
migration_subcategory
from ayocasn.apps.categories.models import Category, Subcategory
# Migration subcategory
cat_id_2 = Category.objects.get(id=2)
cat_id_2.id = 4
cat_id_2.save()
Subcategory.objects.filter(category_id=2).update(category_id=4)
cat_id_1 = Category.objects.get(id=1)
cat_id_1.id = 2
cat_id_1.save()
Subcategory.objects.filter(category_id=1).update(category_id=2)
Category.objects.filter(id=1).delete()
cat_id_4 = Category.objects.get(id=4)
cat_id_4.id = 1
cat_id_4.save()
Subcategory.objects.filter(category_id=4).update(category_id=1)
Category.objects.filter(id=4).delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment