Ticket #13211: groups.diff

File groups.diff, 2.1 KB (added by CrazyGir, 4 years ago)

updated original diff to apply against current trunk

  • docs/topics/auth.txt

     
    14341434
    14351435.. currentmodule:: django.contrib.auth
    14361436
     1437Programmatically creating permissions
     1438-------------------------------------
     1439
     1440While custom permissions can be defined within a model's ``Meta`` class, you
     1441can also create permissions directly. For example, you can create the ``can_publish``
     1442permission for a ``BlogPost`` model in ``myapp``::
     1443
     1444    from django.contrib.auth.models import Group, Permission
     1445    from django.contrib.contenttypes.models import ContentType
     1446
     1447    content_type = ContentType.objects.get(app_label='myapp', model='BlogPost')
     1448    perm = Permission.objects.create(codename='can_publish', name='Can Publish Posts',
     1449         content_type=content_type)
     1450
     1451The permission can be assigned to a :class:`~django.contrib.auth.models.User` via
     1452``user_permissions`` or a :class:`~django.contrib.auth.models.Group` via
     1453``permissions``.
     1454
     1455
    14371456Authentication data in templates
    14381457================================
    14391458
     
    15261545access to a members-only portion of your site, or send them members-only email
    15271546messages.
    15281547
     1548API reference
     1549-------------
     1550
     1551.. class:: models.Group
     1552
     1553    As with both users and permissions, groups are implemented in a Django model
     1554    that lives in `django/contrib/auth/models.py`_.
     1555
     1556.. _django/contrib/auth/models.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/models.py
     1557
     1558Fields
     1559~~~~~~
     1560
     1561:class:`~django.contrib.auth.models.Group` objects have the following fields:
     1562
     1563.. attribute:: models.Group.name
     1564
     1565    Required. 80 characters or fewer. Any characters are permitted. Example:
     1566    ``'Awesome Users'``.
     1567
     1568.. attribute:: models.Group.permissions
     1569
     1570    Many-to-many field to :class:`~django.contrib.auth.models.Permissions`::
     1571
     1572        group.permissions = [permission_list]
     1573        group.permissions.add(permission, permission, ...)
     1574        group.permissions.remove(permission, permission, ...)
     1575        group.permissions.clear()
     1576
    15291577.. _authentication-backends:
    15301578
    15311579Other authentication sources
Back to Top