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?

Mike
  • 13
  • 2

1 Answers1

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.

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121