Am new to Django, have been working on linking some permissions to groups and then adding users to those groups. Have managed some of that so far, but am stuck on understanding exactly what is going on with the permissions. Here is my attempt so far:
(Django-1.11.4-env) $ python manage.py shell
Python 3.6.7 (default, Oct 25 2018, 13:09:20)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.auth.models import Permission
>>> p = Permission.objects.all()
then
>>> p.values
<bound method QuerySet.values of <QuerySet [<Permission: MyApp | user | Can add user>, <Permission: MyApp | user | Can write stuff.>, <Permission: MyApp | user | Can change user>, <Permission: MyApp | user | Can delete user>, <Permission: admin | log entry | Can add log entry>, <Permission: admin | log entry | Can change log entry>, <Permission: admin | log entry | Can delete log entry>, <Permission: auth | group | Can add group>, <Permission: auth | group | Can change group>, <Permission: auth | group | Can delete group>, <Permission: auth | permission | Can add permission>, <Permission: auth | permission | Can change permission>, <Permission: auth | permission | Can delete permission>, <Permission: contenttypes | content type | Can add content type>, <Permission: contenttypes | content type | Can change content type>, <Permission: contenttypes | content type | Can delete content type>, <Permission: sessions | session | Can add session>, <Permission: sessions | session | Can change session>, <Permission: sessions | session | Can delete session>]>>
then
>>> p.values()
<QuerySet [{'id': 16, 'name': 'Can add user', 'content_type_id': 6, 'codename': 'add_user'}, {'id': 19, 'name': 'Can write stuff.', 'content_type_id': 6, 'codename': 'can_write'}, {'id': 17, 'name': 'Can change user', 'content_type_id': 6, 'codename': 'change_user'}, {'id': 18, 'name': 'Can delete user', 'content_type_id': 6, 'codename': 'delete_user'}, {'id': 1, 'name': 'Can add log entry', 'content_type_id': 1, 'codename': 'add_logentry'}, {'id': 2, 'name': 'Can change log entry', 'content_type_id': 1, 'codename': 'change_logentry'}, {'id': 3, 'name': 'Can delete log entry', 'content_type_id': 1, 'codename': 'delete_logentry'}, {'id': 7, 'name': 'Can add group', 'content_type_id': 3, 'codename': 'add_group'}, {'id': 8, 'name': 'Can change group', 'content_type_id': 3, 'codename': 'change_group'}, {'id': 9, 'name': 'Can delete group', 'content_type_id': 3, 'codename': 'delete_group'}, {'id': 4, 'name': 'Can add permission', 'content_type_id': 2, 'codename': 'add_permission'}, {'id': 5, 'name': 'Can change permission', 'content_type_id': 2, 'codename': 'change_permission'}, {'id': 6, 'name': 'Can delete permission', 'content_type_id': 2, 'codename': 'delete_permission'}, {'id': 10, 'name': 'Can add content type', 'content_type_id': 4, 'codename': 'add_contenttype'}, {'id': 11, 'name': 'Can change content type', 'content_type_id': 4, 'codename': 'change_contenttype'}, {'id': 12, 'name': 'Can delete content type', 'content_type_id': 4, 'codename': 'delete_contenttype'}, {'id': 13, 'name': 'Can add session', 'content_type_id': 5, 'codename': 'add_session'}, {'id': 14, 'name': 'Can change session', 'content_type_id': 5, 'codename': 'change_session'}, {'id': 15, 'name': 'Can delete session', 'content_type_id': 5, 'codename': 'delete_session'}]>
Of all the permissions here, most of them were part of Django but the one with name 'Can write stuff.'
I added previously.
So the output of p.values() is relatively intuitive, each permission has a set of keys and values linked to it.
Am really stuck though on understanding the output of p.values
<Permission: MyApp | user | Can add user>
<Permission: admin | log entry | Can add log entry>
<Permission: contenttypes | content type | Can add content type>
<Permission: sessions | session | Can change session>
<Permission: auth | permission | Can add permission>
Only the third part of each of these elements of the QuerySet after the pipe is found in the dictionaries from p.values() under 'name', eg 'Can add user'
What is the meaning of the first and second part of each of these?