The Frobshop tutorial says: “For a deployment setup, we recommend creating product classes as data migration.”
The link points a high-level and abstract document that is more aspirational than instructive. At this point in the tutorial, no information has yet been provided on how to create a data migration. Googling and searching for this information looks like it will take many hours to figure out how to follow the recommendation.
What is the recommended way to create product classes as a data migration, in detail?
The article linked to in the documentation is quite old and has since been superseded by Django's own support for data migrations, which is documented here.
The Django documentation for these does a decent job of explaining what they are and how to create them, so assuming that you've read that, then this is the sort of thing that is being suggested in the tutorial:
python manage.py makemigrations --empty yourappname
from django.db import migrations
def populate_product_classes(apps, schema_editor):
ProductClass = apps.get_model('catalogue', 'ProductClass')
books = ProductClass.objects.create(name='Books')
toys = ProductClass.objects.create(name='Toys')
# ... etc. You could also load data from a fixture here,
# and may also want to create attributes for each class as well, e.g.,
ProductAttribute = apps.get_model('catalogue', 'ProductAttribute')
ProductAttribute.objects.create(product_class=books, name='ISBN', code='isbn', type='text')
class Migration(migrations.Migration):
dependencies = [
('catalogue', '0022_auto_20210210_0539'), # This needs to be after Oscar's catalogue migrations
]
operations = [
migrations.RunPython(combine_names),
]
After this has been created, executing manage.py migrate
on your project will run this migration and populate the database with the product classes/attributes.