0

My goal is:

  • to have created custom Groups and populated with permissions for specific models. All that immediately after or during application starts

Question:

  • What is the most appropriate way to achieve that?

For example my custom group is MY_CUSTOM_GROUP and i want to add change and view permissions for Model Book to that group

Ivan
  • 55
  • 8
  • A fixture would be appropriate for your use-case https://docs.djangoproject.com/en/3.1/howto/initial-data/ – Iain Shelvington Jan 17 '21 at 09:45
  • @Iain Shelvington And why not to write manual migration? What is the advantage of fixture over manual migration? – Ivan Jan 17 '21 at 15:42

1 Answers1

0

Just ran into that problem myself. The standard way to do it is either by creating a custom migration or through fixtures. Groups and permissions added through a custom migration will be available without any additional commands. The downside might be that the process of migrations rebuild will now be more complicated (I am a noob at django too, so please correct me if I'm wrong here). Fixtures require running a manage.py command to prepopulate the database, but they come with the advantage of being completely decoupled from migrations.

  • This question has a useful example of making a custom migration: https://stackoverflow.com/questions/25024795/django-1-7-where-to-put-the-code-to-add-groups-programmatically – Anton Bernatskiy Jan 27 '21 at 07:09