On 1/24/06, greg <[EMAIL PROTECTED]> wrote:
> That works fine,nowin my template when i do {{recette.difficulte }} i
> got the number 1,2 or 3 not the name of the difficulty.
> SInce DIFFICULTY_CHOICES is not defined as a global variable and it is
> not allowed to put DIFFICULTY_CHOICES in class;
> the following trick doesnt work.
>
> def category_name(self, number):
>      return CATEGORY_CHOICES[number][1]
>
> What is a good solution to get the corresponding name associated to the
> number ?

Every field that has "choices" set will automatically put a
get_FIELDNAME_display() method on the model. In your example, your
model objects will have a get_difficulte_display() method.

http://www.djangoproject.com/documentation/db_api/#get-foo-display

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Reply via email to