django-modelswagtailwagtail-snippet

What is the best way to setup default snippets in Wagtail


I would like to setup default snippets (article categories) in a Wagtail blog project.

My option would be to add the following line at the end of the models.py module:

if BlogPageCategory.objects.filter(name = 'Association').count() == 0:
    category = BlogPageCategory(name='Association')
    category.save()

Is it the best way to do it? Would it have any impact on the site performance?

Thanks


Solution

  • There are multiple ways to achieve what you want: