Skip to content


name attribute for NoticeType #3

zerok opened this Issue · 3 comments

1 participant


Reported by jjconti, May 22, 2008

I suggest a new attribute for NoticeType: name.

If label is "Información" name should be "informacion"
If label is "Birthday Greet" name should be "birthday_greet"

Django cames with a function to perform this stuff but I am not sure if the
name should be forced or defined by the user. In any case, I'll really
appreciate that attribute because it'll allow me to do this at Notice:

def __getattr__(self, attrname):
       label = attrname[len('is_'):]
           notice_type = NoticeType.objects.get(label=label)
           return (lambda: True)
       except NoticeType:
           return (lambda: False)
       super(Notice, self).__getattr__(attrname)

Playing in the shell:

>>> from notifications.models import *
>>> n = Notice.objects.get(id=1)
>>> n.is_foo()
>>> n.notice_type
<NoticeType: informacion>
>>> n.is_informacion()

These methods without arguments will be very useful at templates, where you
can ask if a Notice is_sometype and then render "class=sometype" for css stuff.



This as already been solved with the 'display' field.

You should also look at Pinax -- site at and code
under django-hotclub -- for an example of how I'm using django-notification at the



I am happy to change the names 'label' and 'display' to something that better shows
one is the unique key and one is the display name.



auth.Permission use name and codename for that propose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.