[Answer]-How to add user group in django?

1👍

It’s perfectly fine to add groups using the admin interface – in fact that’s what the admin interface is for.

Putting that code in __init__.py makes absolutely no sense. That file is run every time it’s module is imported (or the first time in each request, don’t know the exact mechanics). So then you would try to create the same group during each separate request.

However, that code can be used in a python shell – just execute it once and the groups are created in the database. Just invoke a Django-specific Python shell using manage.py shell, and start typing. However, it might be easier to add the right permissions through the admin interface. If you don’t care about permissions and just want users grouped together, this way is just as fine.

👤knbk

Leave a comment