I am currently learning Python and Django via building a simple Web 
application. It involves objects with character fields that take values in 
different languages (French and Spanish) and I face an issue with sorting 
on those values in the Django administration site. 

Here are sample sets:
French: dataFr = ['être', 'gronder', 'gérer', 'éviter', 'exiger']
Spanish: dataEs = ['dos', 'acompasar', 'acompañar', 'día']

The following works fine in Python:

import locale
locale.setlocale(locale.LC_ALL,"fr_FR.utf8") 
sorted(dataFr, key=locale.strxfrm) 
> ['être', 'éviter', 'exiger', 'gérer', 'gronder'] #which is the desired 
result.
sorted(dataEs, key=locale.strxfrm)
> ['acompañar', 'acompasar', 'día', 'dos'] #which is also the desired 
result.

(French as well as Spanish local settings seem to work indifferently for 
sorting  French and Spanish)

In Django, the simplified model is as follows:

from django import models

class Word(models.Model):
    content = models.CharField(max_length=32, unique=True)
    class Meta:
        abstract = True
        
class FrenchWord(Word)
        
The relevant part of the admin.py file is:

from django.contrib import admin
from .models import FrenchWord

@admin.register(FrenchWord)
class FrenchWord(admin.ModelAdmin):
    list_display = ('content',)
    ordering = ('content',)

Now my question is how to enforce ordering according to the fr_FR.utf8 
locale? I have tried all kinds of stuff, taking inspiration from various 
sites, but I do not succeed.

Thanks in advance.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/865309b0-8869-4542-8ff4-b4941ecd4f47n%40googlegroups.com.

Reply via email to