I’m developing a project on Google AppEngine, using Django templates, so I have to use tags like {{ aitem.Author }} to print content within my HTML template.
Author, however, can either be a string or a list object, and I have no way to tell it in advance. When the Author is a list and I try to print it on my template, I get the ugly result of
Author: [u’J. K. Rowling’, u’Mary GrandPr\xe9′]
Is there any way to handle this kind of scenario (basically printing a field differently depending on its type) effectively? Do I have to rely on custom tags or any other means?
I think the cleanest solution would be to add a method to the model
get_authors()which always returns a list either of one or more authors. Then you can use:If you for some reason have only access to the templates and can’t change the model, then you can use a hack like this:
P.S. it’s not a good convention to use capital letters for attribute names.