Dynamic queryset using request.POST data in class-based generic views

余生颓废 提交于 2019-12-11 08:45:30

问题


I'm interested in how to make dynamic queryset using request.POST query dict? When I did that:

class ListCv(ListView):
    queryset = CV.objects.all()
    template_name = 'jobseek/applicants_resumes_list.html'  
    paginate_by = 5

    def get_context_data(self, **kwargs):
        context = super(ListCv, self).get_context_data(**kwargs)
        context['main_form'] = FilterCV(self.request.POST or None)
        return context

    def get_queryset(self):
        request = self.request
        main_form = FilterCV(request.POST or None)

        if main_form.is_valid():
            cleaned_fields = main_form.cleaned_data                 

            query_tag = cleaned_fields.get('query_tag')            

            lookup = (~Q(position__icontains=query_tag)| 
                      ~Q(additional_information__icontains=query_tag)|
                      ~Q(title__icontains=query_tag))
            return CV.objects.filter(lookup)
        return CV.objects.all()

I have got blank white page without any exceptions. Can I use FormMixin, ProcessFormView for solve my issue? If I can, how?

edit

template:

<div class="vacancies_list">
    {% for object in object_list %}               
        <div class="vacancy">
           <div class="title"><a href="{% url view_cv object.id %}" title="">{{     object.title }}</a></div>
           <div class="body">
           {{ object.employment_type }}; 
           {% for education in object.highereducation_set.all %}
           {{ education.faculty }}: {{ education.specialty }}
           {% endfor %}
           {% for experience in professionalexperience_set.all %}
           {{ experience.company_name }}: {{ experience.position }}
           {% endfor %}...
           &nbsp;<a href="{% url view_cv object.id %}" title="" class="more">Полное     описание<img src="{{ STATIC_URL }}images/arrow_right_green.png" alt=">" title="" /></a>
           </div>
        </div>
     {% endfor %}       
  </div>

来源:https://stackoverflow.com/questions/8216980/dynamic-queryset-using-request-post-data-in-class-based-generic-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!