djangosnippets.org: Latest snippets tagged with 'group'https://djangosnippets.org/tags/group/2022-12-19T11:51:50.631290-06:00Add custom fields to the built-in Group model
2022-12-19T11:51:50.631290-06:00jmoppelhttps://djangosnippets.org/snippets/10945/<p>Add fields and extend Django's built-in <code>Group</code> model using a <code>OneToOneField</code> (i.e. a profile model). In this example, we add a <code>UUIDField</code>. Whenever a new group is created, we automatically (via signals) create a corresponding <code>Role</code> record referencing the newly created group. Whenever a Group is deleted, the corresponding …</p>
Freely redistributableGroup permissions selection in admin filtered by your app models
2014-02-04T19:40:38.254872-06:00estecbhttps://djangosnippets.org/snippets/3024/<p>Sometimes you just don't want to display every permission django has, you just want a short list showing the permissions for some of your apps (or even django core apps).</p>
<p>GROUP_PERMISSIONS_MODELS must be a list of your app models. Dotted path (in lowercase) required, app name + model <em>class</em> name.</p>
Freely redistributableUser groups template tag with "else" block support (Allow checking several groups)
2012-04-29T06:44:33.301246-05:00br0th3rhttps://djangosnippets.org/snippets/2736/<p>An "if-style" template tag that checks to see if a user belongs to a one or mores groups (by name).</p>
<p>Usage:
<code>{% ifusergroup Admins %} ... {% endifusergroup %}
or
{% ifusergroup Admins Clients Programmers Managers %} ... {% else %} ... {% endifusergroup %}</code></p>
Freely redistributableUser groups template tag
2011-10-09T06:13:33.238247-05:00daveahttps://djangosnippets.org/snippets/2566/<p>This snippet is an improved version of the <a href="http://djangosnippets.org/snippets/1576/">ifusergroup</a> tag that allows spaces in any of the group names. It also fixes a small bug where if a group didn't exist none of the subsequent groups would be checked.</p>
Freely redistributableUser groups template tag
2009-06-18T08:54:14.409384-05:00hijinkshttps://djangosnippets.org/snippets/1576/<p>This tag builds on top of the <a href="http://www.djangosnippets.org/snippets/390/">ifusergroup/else tag</a>, fixes a small bug and introduces support for else blocks. This adds a way to provide multiple groups via group1|group2|group3</p>
Freely redistributableTemplate tag: Group variables into list
2009-03-13T14:14:00.795410-05:00Killarnyhttps://djangosnippets.org/snippets/1369/<p>Groups an arbitrary number of variables into a list.</p>
<p><code>{% group "foo", 2, "bar" as my_list %}</code></p>
Freely redistributableCheck Group Membership Filter
2008-07-18T14:48:03.596759-05:00Moggahttps://djangosnippets.org/snippets/895/<p>Derived from <a href="http://www.djangosnippets.org/snippets/847/">847</a> but allows for checks against multiple groups...</p>
Freely redistributableLDAP to Django Synchronization
2008-07-18T12:13:00.834040-05:00Moggahttps://djangosnippets.org/snippets/893/<p>I needed to be able to synchronize my LDAP users and groups to the Django database. This may not be as efficient as some might like but it works like a charm. It returns a list of messages that I pipe into request.user.messages in my template.</p>
Freely redistributablein_group template filter
2008-07-02T16:45:34.894554-05:00whiteingehttps://djangosnippets.org/snippets/847/<p>Allows you to search if a user belongs to a given group.</p>
<p>Along the same lines as snippet <a href="http://www.djangosnippets.org/snippets/390/">390</a>, but uses a regular <code>if</code> tag so it is more flexible.</p>
<p>(Updated for efficiency. Running a boolean test on a QuerySet avoids a bit of unnecessary overhead.)</p>
<p>(Updated to accept …</p>
Freely redistributableUser group template tag with "else" block support
2007-08-26T18:50:06.382952-05:00GomoXhttps://djangosnippets.org/snippets/390/<p>This tag builds on top of the <a href="http://www.djangosnippets.org/snippets/282/">ifusergroup tag</a>, fixes a small bug and introduces support for else blocks.</p>
Freely redistributableUser group template tag
2007-06-13T08:59:21.328451-05:00jdriscollhttps://djangosnippets.org/snippets/282/<p>An "if-style" template tag that checks to see if a user belongs to a specific group (by name).</p>
Freely redistributable