I want create migrations for create collections applying one migration.
I haven't clear which is the properly workflow for create collections since python code, can anyone help to me?
I want create migrations for create collections applying one migration.
I haven't clear which is the properly workflow for create collections since python code, can anyone help to me?
Ok, searching in the web i found two solutions: one in google mailing list, and other here in StackOverflow.
After test the code in the shell we can see that it works for create collections:
from wagtail.wagtailcore.models import Collection
root_coll = Collection.get_first_root_node()
root_coll.add_child(name='testcoll')
Now we can use this code but in a migration, so, create a new empty migration with ./manage.py makemigrations home --empty
and add inside the previous code:
from __future__ import unicode_literals
from django.db import migrations
from wagtail.wagtailcore.models import Collection
def create_collections(apps, schema_editor):
names = [
'video tutoriales',
'videos personal',
'videos varios',
'imagenes tutoriales',
'imagenes personal',
'imaganes varias',
'documentos tutoriales',
'documentos personal',
'documentos varios'
]
# Get models
# Get collection's root
root_collection = Collection.get_first_root_node()
for name in names:
root_collection.add_child(name=name)
class Migration(migrations.Migration):
dependencies = [
('home', '0002_create_homepage'),
]
operations = [
migrations.RunPython(create_collections),
]
First, we get the main Collection
node in a variable, after we add whatever amount of child with his respective name.
Is a very basic code actually.
If anyone can optimize it, your welcome, thank you.
Does something as mentioned here would work?
How to squash recent Django migrations?
python manage.py squashmigrations <appname> <squashfrom> <squashto>
Regards