Question

The template is rendering this:

Hello, [<Student: Bob Frediricko>]. How are you?

But I want it to render:

Hello, Bob. How are you?

The view does this:

q = Student.objects.filter(pk=1)

for f in survey_formset:
    f.helper.layout = Layout(HTML("""
                    Hello, {{ q }}. How are you?
                    """))

the student model has...

def __unicode__ (self):
    return smart_unicode(self.first_name+" "+self.last_name)

Thanks for the help :]

Was it helpful?

Solution

filter returns a list, which is what you are seeing stringified in your rendered template.

Try this instead:

q = Student.objects.filter(pk=1)[0]

Or better yet, since you are selecting by pk (which is unique):

q = Student.objects.get(pk=1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top