Django Records for Permissions

I create permission devices in Django. I can download them as needed. However, my question is: .. I want to download the fixture for the table auth_group_permissions, I need to specify group_idand permission_id, unfortunately, fixtures are not the best way to handle this. Is there an easier way to do this programmatically? So that I can get idfor certain values ​​and fill them out? How is this usually done?

+5
source share
2 answers

The right decision is to create permissions in the same way as the framework itself.

You need to connect to the built-in signal post_syncdbeither in the module management.py, or management/__init__.pycreate permissions there. The documentation says that any work performed in response to the signal post_syncdbshould not make any changes to the database, but you should also note that the frame itself creates permissions in response to this signal.

Therefore, I suggest you take a look at the application control moduledjango.contrib.auth to see how this should be done.

+8
source

At least Django> = 1.7, the accepted answer is no longer the correct answer due to the introduction of "natural keys" as a serialization option.

For more information on natural keys, see the Django serialization documentation.

, ...

... Django , ; , . , , , .

, , auth_group_permissions, :

python manage.py dumpdata auth --natural-foreign --natural-primary -e auth.Permission

auth_permissions -e, migrate .

,

+4

All Articles