1
如何在這種情況下獲得最新的對象?在這種情況下如何獲取最新的對象?
{% 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'),
)
myevent_set被訂購desc時間?如果是這樣,你可以做'myevent_set.all.0' –