Reputation: 986
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
Upvotes: 2
Views: 230
Reputation: 5405
There are multiple ways to achieve what you want:
AppConfig's
ready()
method (as described here), as that is most commonly the place to run any code upon server startup. It won't have a very big impact on performance, because it is only run once (When your server is started)Upvotes: 3