Wednesday, May 28, 2014

Re: Model field's verbose_name from database?

from django.utils.functional import lazy

def field_verbose_db(field_name):
    from app.models import FieldNamesMap
    return FieldNamesMap.objects.get(key=field_name).title

field_verbose_db_lazy = lazy(field_name, unicode)

first_name = models.CharField(..., verbose_name=field_verbose_db_lazy('first_name')) 

вторник, 4 февраля 2014 г., 22:03:08 UTC+4 пользователь Jon Dufresne написал:
Hi,

I have a model with fields that allows the user to modify the
user-facing names of these fields. Think "first name", "last name",
"email", the user may prefer these be displayed as "given name",
"surname", "email address". This is configured exactly once throughout
the system. So in this example *all* instances of "first name" should
instead be displayed as "given name". Is it possible have a model
where "verbose_name" is not a static string, but instead comes from
the database? Perhaps with some lazy loading trickery? I want to do
something in the spirit of:

first_name = models.CharField(..., verbose_name=lazy_load_name_from_db())

My hope is to eliminate the need to think about what to call this
field when displayed to the user.

Thanks,
Jon

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/18b0c5bc-71c3-42d7-841e-3afd13c0bd71%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment