2

In a template, I want to show the data of all objects related to the "source-object".

This is the model of the Events that I want to show on the Article detail page:

### Models ###
class EventRecord(models.Model):
    article = models.ForeignKey(Article, related_name='events')
    event_date = models.DateField('Event Date')
    country = models.CharField(blank=True, max_length=100)
    location = models.CharField(blank=True, max_length=100)
    actors = models.CharField(blank=True, max_length=100)
    .
    .
    .
    def __unicode__(self):
        return self.event_date

This is the view I wrote for it (this works):

### View ###
def article_detail(request, pk):
    """ Detail View for articles"""
    article = get_object_or_404(Article, pk=pk)
    events = article.events.all()

    return render(request, 'coding/article-detail.html', {'article': article,
    'events': events})
    pass

This template works too, but all I see is the event_date info.

### Template ### 
<div>
<h2>Events</h2>
{% for event in events %}
    {{ event }}
{% endfor %}

</div>

Is this because of__unicode__(self)?
What do I have to do to see all the event info?

Thanks a lot!

4

1 に答える 1