Skip to content

Commit

Permalink
Update django docs
Browse files Browse the repository at this point in the history
  • Loading branch information
omidraha committed Dec 23, 2018
1 parent e2d5230 commit c370ff1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/django/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,37 @@ Translation
txt = 'Hello'
ugettext(txt)
'سلام'
Django User Group Permissions
-----------------------------


Add permission to user

.. code-block:: python
from django.contrib.auth.models import Permission
perm = Permission.objects.get(name='Can edit org')
u.user_permissions.add(perm)
Add user to group

.. code-block:: python
from django.contrib.auth.models import Group
grp = Group.objects.get(name='Operator')
grp.user_set.add(your_user)
Add permission to group

.. code-block:: python
from django.contrib.auth.models import Group
from django.contrib.auth.models import Permission
perm = Permission.objects.get(name='can edit org')
grp = Group.objects.get(name='Operator')
grp.permissions.add(perm)

0 comments on commit c370ff1

Please sign in to comment.