Django dynamic filtered ListView返回错误:get()为参数';获取了多个值;自我';
我需要一些人帮忙解决这个问题。我想我正在做django docs()建议的事情,但我一直遇到这个错误:get()为参数“self”获取了多个值 教科书列表.htmlDjango dynamic filtered ListView返回错误:get()为参数';获取了多个值;自我';,django,django-views,django-templates,django-generic-views,Django,Django Views,Django Templates,Django Generic Views,我需要一些人帮忙解决这个问题。我想我正在做django docs()建议的事情,但我一直遇到这个错误:get()为参数“self”获取了多个值 教科书列表.html <a href="{% url 'lesson_list' textbook.pk %}"> <button type="button" class="btn btn-info">More Info</button> </a
<a href="{% url 'lesson_list' textbook.pk %}">
<button type="button" class="btn btn-info">More Info</button>
</a>
使用
self=…
没有多大意义,您希望在主键上进行筛选,因此:
class TextbookLessonList(ListView):
template_name = 'textbook_lesson_list.html'
def get_queryset(self):
self.textbook = get_object_or_404(Textbook, pk=self.kwargs['pk'])
return TextbookLesson.objects.filter(textbook=self.textbook)
你是上帝,先生。非常感谢你!
class TextbookLessonList(ListView):
template_name = 'textbook_lesson_list.html'
def get_queryset(self):
self.textbook = get_object_or_404(Textbook, self=self.kwargs['pk']) #This is the offending line
return TextbookLesson.objects.filter(textbook.pk==self.textbook)
class TextbookLessonList(ListView):
template_name = 'textbook_lesson_list.html'
def get_queryset(self):
self.textbook = get_object_or_404(Textbook, pk=self.kwargs['pk'])
return TextbookLesson.objects.filter(textbook=self.textbook)
class TextbookLessonList(ListView):
template_name = 'textbook_lesson_list.html'
model = TextbookLesson
def get_queryset(self, *args, **kwargs):
return super().get_queryset(*args, **kwargs).filter(
textbook_id=self.kwargs['pk']
)