0

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",)

1 Answer 1

1
u', '.join(group.someattr for group in self.userprofile.client.get_groups())
Sign up to request clarification or add additional context in comments.

1 Comment

I ran your line and it worked. Just for curiosity, I ran my original code in the shell and compared my output with the new output. There is no difference as far I can tell. Could you explain why your code works, other than the fact that you joined the group items with a 'unicoded' comma-space ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.