Dynamic queryset using request.POST data in class-

2019-07-24 20:32发布

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>

0条回答
登录 后发表回答