You know? you are superb!!!

Arnold

On Jul 25, 7:19 am, "Wolfram Kriesing" <[EMAIL PROTECTED]>
wrote:
> and i forgot, this allows you to access the property "name" of the
> object anywhere seemlessly, in the template, in the code, etc. this is
> pretty neat imho :-)
>
> wolfram
>
> On 7/25/07, Wolfram Kriesing <[EMAIL PROTECTED]> wrote:
>
>
>
> > after some investigation and help from the list i took this approach
> > and have to say it works great:
>
> > from django.utils import translation
>
> >     @property
> >     def name(self):
> >         if translation.get_language()=="en":
> >             return self.name_en
> >         else:
> >             return self.name_de
>
> > good luck
>
> > wolfram
>
> > On 7/25/07, Arnold Chen <[EMAIL PROTECTED]> wrote:
>
> > > I am implementing a multi-lingual product catalog website with Django.
> > > It is in English (default), Trad. Chinese and Simp. Chinese. I want to
> > > let user to choose the language they want, and the system display the
> > > corresponding product name (in the selected language).
>
> > > The product class is something like
>
> > > # ======= start class =============
> > > class Product(models.Model)
> > >    name_en = mode.CharField()
> > >    name_tw = mode.CharField()
> > >    name_cn = mode.CharField()
>
> > >    def get_name(self, lang="en"):
> > >          return eval("self.name_" + lang)
>
> > > # ======= end class =============
>
> > > The language preference that user has chosen will be saved in
> > > request.session['django_language']
>
> > > Of cos, i don't know how to use the get_name() function that i've
> > > implemented, because i can't pass the lang from view or template. So,
> > > the question is how do i get the request.session['django_language']
> > > variable in models ? or is there any other way to achieve the desired
> > > result?
>
> > > Thanks in advance.
> > > Arnold
>
> > --
> > cu
>
> > Wolfram
>
> --
> cu
>
> Wolfram


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to