Ticket #13211: 13211.diff

File 13211.diff, 2.0 KB (added by John Paulett, 14 years ago)

Add Group API reference and Permission API example

  • docs/topics/auth.txt

    diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
    index 52ddf22..df8ad50 100644
    a b data-access methods like any other :doc:`Django model </ref/models/instances>`.  
    12951295
    12961296.. currentmodule:: django.contrib.auth
    12971297
     1298
     1299Programmatically creating permissions
     1300-------------------------------------
     1301
     1302While custom permissions can be defined within a model's ``Meta`` class, you
     1303can also create permissions directly. For example, you can create the ``can_publish``
     1304permission for a ``BlogPost`` model in ``myapp``::
     1305
     1306    from django.contrib.auth.models import Group, Permission
     1307    from django.contrib.contenttypes.models import ContentType
     1308
     1309    content_type = ContentType.objects.get(app_label='myapp', model='BlogPost')
     1310    perm = Permission.objects.create(codename='can_publish', name='Can Publish Posts',
     1311         content_type=content_type)
     1312
     1313The permission can be assigned to a :class:`~django.contrib.auth.models.User` via
     1314``user_permissions`` or a :class:`~django.contrib.auth.models.Group` via
     1315``permissions``.
     1316
     1317
    12981318Authentication data in templates
    12991319================================
    13001320
    group ``'Special users'``, and you could write code that could, say, give them  
    13871407access to a members-only portion of your site, or send them members-only e-mail
    13881408messages.
    13891409
     1410.. class:: models.Group
     1411
     1412API reference
     1413-------------
     1414
     1415Fields
     1416~~~~~~
     1417
     1418.. class:: models.Group
     1419
     1420    :class:`~django.contrib.auth.models.Group` objects have the
     1421    following fields:
     1422
     1423    .. attribute:: models.Group.name
     1424
     1425        Required. 80 characters or fewer. Any characters are permitted.
     1426
     1427    .. attribute:: models.Group.permissions
     1428
     1429        Many-to-many field to :class:`~django.contrib.auth.models.Permissions`::
     1430
     1431            group.permissions = [permission_list]
     1432            group.permissions.add(permission, permission, ...)
     1433            group.permissions.remove(permission, permission, ...)
     1434            group.permissions.clear()
     1435
    13901436Messages
    13911437========
    13921438
Back to Top