Hi there,

Spent hours trying to find the solution, but no luck. So here goes...

Please consider simplified code below:

{{{
class Country(models.Model):
    ...
    label_en = models.CharField(max_length = 128, blank=True,
null=True)
    label_nl = models.CharField(max_length = 128, blank=True,
null=True)

    class Meta:
        ordering = ('label_en',)

    def __unicode__(self):
        if hasattr(settings, 'LANGUAGE_CODE'):
            field = 'label_%s' % settings.LANGUAGE_CODE.lower()
            if hasattr(self, field):
                return getattr(self, field)
        return self.label_en
}}}

Other models use Country with a ForeignKey relationship. The
__unicode__ function works for displaying localized country names. If
LANGUAGE_CODE is 'nl' then the drop down selectbox for Country in the
admin shows Dutch country names, otherwise all country names are
English.

But it's not exactly what you'd want. Now I want to be able to do two
things:

 1. Change __unicode__ to use request.LANGUAGE_CODE, the user
preference.
 2. Change ordering to the chosen language field. You don't want a
list in Dutch, ordered by English translations.

All this is happening runtime, of course. Users in a admin edit page,
using a drop down for the foreign key Country, should see the country
names and ordering change when they select another language.

Possible? Other ways to achieve a runtime language dependent model?

Thanks in advance,

Wouter

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to