Because I use many of the same constants in different apps in my project I keep most of them including almost all choices in a single __init__.py file and import them wherever required.

Here is a tiny utility I use all the time ... whenever get_<fieldname>_display() is inappropriate.


def choose(choices, choice):
    for pair in choices:
        if pair[0] == choice:
            return pair[1]
    for section in choices:
        for pair in section[1]:
            if pair[0] == choice:
                return pair[1]


Hope someone finds it useful. Also, I'm sure it can be made much more pythonic. It is Friday after all :)

Cheers

Mike




--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fe15d311-84bf-99fc-1511-767c83572e3b%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to