2
내 코드는 다음과 같다 : I 사용자 정의 내 상황과 내 쿼리 템플릿 설정에 액세스 할장고 액세스 컨텍스트는
class GetStudentQueryHandler(ListView):
template_name = 'client.html'
paginate_by = STUDENT_PER_PAGE
context_object_name = 'studentinfo'
def get_context_data(self, **kwargs):
context = super(GetStudentQueryHandler, self).get_context_data(**kwargs)
context['can_show_distribute'] = self.request.user.has_perm('can_show_distribute_page')
context['form'] = QueryStudentForm
return context
def get_queryset(self):
질문입니다 다음 get_queryset 방법에 의해 반환 된 검색어 세트에 액세스하는 방법 템플릿? 나는 정의가 어떻게 쿼리 데이터에 액세스하는 studentinfo.can_show_distribute, 같은 속성에 액세스 할 수 있습니다 알아? (로 또한
{% for obj in objects_list%}
{{obj.some_field}}
{% endfor %}
, 그것은 context_object_name
매개 변수를 사용하여 수동으로 설정할 수 있습니다 : 그것은 here 서면으로
나는 것을 알고,하지만 난 get_context_data 방법에 내 상황을 customed 한 나는 for 루프, 나 또한 사용자 정의 필드에 액세스 사용하는 경우, 내가 'can_show_distribute', 난 두려워처럼 필드를 추가,하지만 난 get_queryset 메소드가 리턴 한 데이터를 표시하기 만하면됩니다. –
글쎄, 당신이했던'컨텍스트 = 슈퍼 (GetStudentQueryHandler, 자기) .get_context_data (** kwargs로)를'. 그래서 컨텍스트는 모든 필드를 포함 할 것이고,'ListView'가 추가합니다. 템플릿에서'can_show_distribute' 액세스하려면이 작업을 수행한다'{{can_show_distribute}}', 그리고이 :'{{studentinfo.can_show_distribute}}' – stalk
은 그래서 당신은 "studentinfo"개체 그냥 get_queryset에 의해 반환 된 검색어 세트를 나타냅니다 의미 방법? 그것이 내가 당신의 대답을 받아 작동하는지 확인 내가 시도해야합니다, 감사합니다 –