chiurox
chiurox

Reputation: 1619

Unicode question in Python with Django

I have a function client_groups in a model that returns a list of "Group" objects:

return self.userprofile.client.get_groups()

Ex. of a returned list:

[<Group: Finance>, <Group: Recepção>,...]

If I just print these normally in a shell, as in, print groups[1], it shows the right thing, which is "Recepção". This function gets used in my admin.py, in my list_display tuple. How can I go about displaying

Finance, Recepção,...

in my Django's admin interface? I tried decoding it but I get an UnicodeEncodeError: 'ascii' codec can't encode characters.

In my admin.py: list_display = ("username","email","first_name","last_name","number","client","client_groups","date_created",)

Upvotes: 0

Views: 201

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798706

u', '.join(group.someattr for group in self.userprofile.client.get_groups())

Upvotes: 1

Related Questions