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:
- Create a data migration in one of your project's apps:
python manage.py makemigrations --empty yourappname
- Add a function to this migration that populates whatever product classes you want to initialise your database with:
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.