如何在单个模板中使用DetailView传递多个模型。
我的观点文件 views.py
from .models import EventDetail, EventTrainer, EventParticipant
class EventDetailView(DetailView):
# model = EventDetail
# template_name = 'event_templates/single_event.html'
def get_context_data(self, *args, **kwargs):
context = super(EventDetailView, self).get_context_data(*args, **kwargs)
return context
答案 0 :(得分:0)
您可以通过context
。
def get_context_data(self, *args, **kwargs):
context = super(EventDetailView, self).get_context_data(*args, **kwargs)
context['event_trainers'] = EventTrainer.objects.all()
context['event_participants'] = EventParticipants.objects.all()
return context