That's what I said. The view should pull out the desired field from
the model based on the language set in the request.

def my_view(request):
    language = request.LANGUAGE_CODE
    category = Category.objects.get(pk=1)  # or whichever you like
    if language == 'en':
        name = category.name_en
    ....

Remark: the code above is not exactly correct. You'd need to extract
the first 2 letters of the language code, as it could be 'en-us' for
example.

On Jun 27, 7:15 pm, "KONTRA, Gergely" <[EMAIL PROTECTED]> wrote:
> Correct me, but I don't think I can access the view from the model.
> So how is this possible?
>
>
>
> On Fri, Jun 27, 2008 at 2:06 AM, Julien <[EMAIL PROTECTED]> wrote:
>
> > I reckon your view should check what the language is set in the
> > request (request.LANGUAGE_CODE), and then pull out the right field
> > from the model.
>
> > On Jun 26, 11:22 pm, pihentagy <[EMAIL PROTECTED]> wrote:
> > > Hi!
>
> > > I have a 3-lingual app, and there are some model fields translated,
> > > like this:
>
> > > class Category(models.Model)
> > >         name_hu = models.CharField(_(u'név (magyar)'), max_length=255,)
> > >         name_en = models.CharField(_(u'név (angol)'), max_length=255)
> > >         name_de = models.CharField(_(u'név (német)'), max_length=255)
>
> > > In some caces __unicode__ method is used for representing data (like
> > > in the admin app, and many other places).
> > > Is there a way I can tell the model about the request's language? Or,
> > > well, I know it is a violation of MVC, but how to solve this problem?
>
> > > thanks
> > > Gergo
>
> --
> +-[ Gergely Kontra <[EMAIL PROTECTED]> ]------------------+
> |                                                           |
> | Mobile:(+36 20)356 9656                                   |
> |                                                           |
> +- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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