Hallöchen! Arien writes:
> On Tue, Jul 15, 2008 at 12:00 PM, Torsten Bronger > <[EMAIL PROTECTED]> wrote: >> >> Arien writes: >> >>> On Tue, Jul 15, 2008 at 10:53 AM, Torsten Bronger >>> <[EMAIL PROTECTED]> wrote: >>> >>>> In a display template (not a form, just display), I write the >>>> following: >>>> >>>> <td>{% trans 'Temperature:' %}</td> >>>> <td>{{ layer.heating_temperature }}</td> >>>> >>>> I'd like to use the verbose_name of the model instance instead >>>> of hard-wiring the label in the template. How can I access it? >>> >>> The verbose_name is at layer._meta.verbose_name. You can't >>> access it like that from your template, though. >> >> Okay, thanks! However, then what is the "official" way to do it? > > [...] > > You'll have to make layer._meta.verbose_name available to the > template under some other name. Unfortunately, I use model polymorphism and model inheritance in this case and can't pass anything but the common base class to the template. Therefore, I collect all verbose_names in an "all_labels" dict in my models.py: all_labels = {} for cls in [cls for cls in _globals.values() if inspect.isclass(cls) and issubclass(cls, models.Model)]: local_labels = {} for field in cls._meta.local_fields: local_labels[field.name] = field.verbose_name all_labels[cls.__name__] = local_labels This I pass to the template, too, so that I can write: <td>{{ all_labels.SixChamberDeposition.heating_temperature }}</td> <td>{{ layer.heating_temperature }}</td> Tschö, Torsten. -- Torsten Bronger, aquisgrana, europa vetus Jabber ID: [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---