在这种情况下如何只获取最新的对象?
{% for entry in instance.event.myevent_set.all %}
....
{% endfor %}
我的尝试:
{% for entry in instance.event.myevent_set.all[0] %}
....
{% endfor %}
但当然不行。
楷模:
class Event(models.Model):
title = models.CharField(max_length=200)
class MyEvent(models.Model):
title = models.CharField(max_length=200)
event = models.ForeignKey(Event)
和我的网址:
urlpatterns = patterns('',
url(r'^$',
ListView.as_view(
queryset=MyEvent.objects.all(),
context_object_name='latest_entry_list',
template_name="blog/index.html"
),
name="blog_list"),
url(r'^(?P<id>\d+)$', 'event.views.single_event'),
)