Thursday, September 1, 2011

Re: custom templatetag that checks groups

See inline:

Cheers

Tom

On Thu, Sep 1, 2011 at 10:38 AM, Szabo, Patrick (LNG-VIE) <patrick.szabo@lexisnexis.at> wrote:

Hi,

 

I want to create my own templatetag that returns true if a user is member of a certain group.

I did the following:

 

Created a package „templatetags" in my app.

Wrote a module:

 

from django import template

register = template.Library()

 

@register.filter 

def check(user):

    if str(user.groups.all()[0]) == "Timesheet-Boss":

        return True

    else:

        return False

 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment