I’m creating fixtures for permissions in Django. I’m able to get them loaded the way it’s needed. However, my question is..say I want to load a fixture for the table auth_group_permissions, I need to specify a group_id and a permission_id, unfortunately fixtures aren’t the best way to handle this. Is there an easier way to do this programmatically? So that I can get the id for particular values and have them filled in? How is this normally done?
I’m creating fixtures for permissions in Django. I’m able to get them loaded the
Share
The proper solution is to create the permissions in the same manner the framework itself does.
You should connect to the built-in
post_migratesignal either in the modulemanagement.pyormanagement/__init__.pyand create the permissions there. The documentation does say that any work performed in response to thepost_migratesignal should not perform any database schema alterations, but you should also note that the framework itself creates the permissions in response to this signal.So I’d suggest that you take a look at the management module of the
django.contrib.authapplication to see how it’s supposed to be done.