2 回答
TA贡献1788条经验 获得超4个赞
class CalendarsOfGroupView(generic.ListView):
model = Calendar
template_name = 'cal/calendarOfGroup.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
group_id = self.kwargs['group_id']
# create var to hold all objects that do not have name==group_id
object_list = Calendar.objects.exclude(name=group_id)
# update the context
context.update({'object_list': object_list})
return context
编辑:过滤日历对象以仅包含匹配的对象group_id
class CalendarsOfGroupView(generic.ListView):
model = Calendar
template_name = 'cal/calendarOfGroup.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
group_id = self.kwargs['group_id']
# create var to hold all objects that do have name==group_id
object_list = Calendar.objects.filter(name=group_id)
# update the context
context.update({'object_list': object_list})
return context
TA贡献1805条经验 获得超9个赞
group_id
或任何其他 URL 参数将在以下位置可用kwargs
:
group_id = self.kwargs['group_id']
get_queryset
您可以在您的方法或您的类可用的任何其他方法中访问它。
添加回答
举报