title: How to filter model results for multiple values dynamically in django
body: <p>I have following course model with professor, code, semester_season, semester_year, etc</p>
  
  <p>I have request post values:</p>
  
  <pre><code>coursecode = request.POST['coursecode']
  courselist = request.POST['courselist']
  semesteryear = request.POST['semesteryear']
  semesterseason = request.POST['semesterseason']
  </code></pre>
  
  <p>this is my filter a queryset for finding above post values:</p>
  
  <pre><code>course_listobj = Course.objects.filter(
    code=coursecode,
    title=courselist,
    semester_year=semesteryear,
    semester_season=semesterseasonid).order_by(
      'code', 'title', 'semester_year', 'semester_season')
  </code></pre>
  
  <p>This is my front end:
  <a href="https://i.stack.imgur.com/wAkOa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wAkOa.jpg" alt="enter image description here"></a></p>
  
  <p>how can find if one post value is empty find other values in query set dynamically i mean</p>
  
  <p>if no post value means <code>coursecode = None</code></p>
  
  <p>here i am finding like below:</p>
  
  <pre><code>if (coursecode != 'None') and (courselist == 'None' and semesteryear == 'None' and semesterseason == 'None'):
      course_listobj = Course.objects.filter(code=coursecode).order_by('code')
  </code></pre>
  
  <p>like above multiple if conditions are required.
  pls suggest me any one how can i do one query with multiple conditions.</p>
  
  <p>Edit (Working code for combination of if conditions):</p>
  
  <pre><code>    coursecode = request.POST['coursecode']
      courselist = request.POST['courselist']
      semesteryear = request.POST['semesteryear']
      semesterseason = request.POST['semesterseason']
  
      courses = Course.objects.all().order_by(
          'code', 'title', 'semester_year', 'semester_season')
  
      coursecodequery = Q(code=coursecode) if coursecode != 'None' else Q()
      courselistquery = Q(title=courselist) if courselist != 'None' else Q()
      semesteryearquery = Q(semester_year=semesteryear) if semesteryear != 'None' else Q()
      semesterseasonquery = Q(semester_season=semesterseason) if semesterseason != 'None' else Q()
  
      course_listobj = courses.filter(
          coursecodequery &amp; courselistquery &amp; semesteryearquery &amp; semesterseasonquery
      )
  
      if coursecode == 'None' and courselist == 'None' and semesteryear == 'None' and semesterseason == 'None':
         messages.info(request, 'Please select all fields')
  
      if not course_listobj:
         messages.info(request, 'No matching courses')
  </code></pre>