I would like to check that certain groups exist in the database after Django starts. If not, the code creates those groups
For example:
from django.contrib.auth.models import Group
def prepare_user_groups():
"""Check that Groups exist, and if not create them"""
group_names = [
"SysAdmins",
"Owners",
"Administrators",
"Sales",
"Accounts",
"Staff",
]
for name in group_names:
if name not in Group.objects.all().values_list("name", flat=True):
Group.objects.create(name=name)
Where should I put this kind of thing? In the app/models.py
or … ?