1

I have something like the following

models.py

class Proposal(models.Model):
terms = models.ManyToManyField('Term')

views.py

data = Proposal.objects.get(pk=id) # is sent to template

template.html

{% for t in  data.terms.all %}
{{ t }}<br />
{% endfor %}

My problem is that I am attempting to embed a variable within {{ t }} For instance a term record {{t}} might look like: "This proposal was created on {{ dateCreated }}"

How can I get the dateCreated variable properly interpreted?

1 Answer 1

0

You should just be able to use the dot syntax to access attributes on the related object:

{{ t.date_created }}

A couple of things to point out: Python attributes are usually snake_case, and doing a foo.related.all() in a template may result in more database queries.

Ah, seems I misunderstood your question.

Sign up to request clarification or add additional context in comments.

Comments

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.