Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 987809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:32:29+00:00 2026-05-16T05:32:29+00:00

I’m filtering a big number of users based on attributes. For example, they can

  • 0

I’m filtering a big number of users based on attributes. For example, they can be filtered by minimum gpa.

So far I’ve been doing the following to construct my queryset-

(‘gpa_gt’ just means that the gpa property has to be greater than whatever is the query param)

    if len(request.GET) != 0:
        kwargs = {}
        if request.GET['mingpa']:
            kwargs['gpa__gt'] = request.GET['mingpa']
    profiles = BlahUser.objects.filter(**kwargs)

Now, the users have a first school major attribute and a second school major attribute. If I filter by a major, I want the user to show up in the results if his first major OR his second major match any of my selections (I use a multiple select on the filtering). What I have now only works for one major-

    if request.GET.has_key('major'):
            kwargs['major__in'] = request.GET.getlist('major')

I know how to explicitly write out the query, but in my case I’m building it dynamically of sorts, and am stumped at how to do so. Any help appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T05:32:29+00:00Added an answer on May 16, 2026 at 5:32 am

    Borgar is definitely on the right track, but I think this is a little closer to what you are
    looking for:

    # filter for minimum GPA
    gpa_filter = Q( gpa__gt=request.GET['mingpa'] )
    major_filter = Q()
    
    if request.GET.has_key('major'):
        majors = request.GET.getlist('major')
        # filter for students with first OR second major in specified majors
        major_filter = Q( first_major__in=majors| Q(second_major__in=majors)
    
    # run filter (these are AND'ed together), so we get students that:
    # 1. Have a first or second major in the specified list of majors AND
    # 2. Have a GPA above the specified minimum
    profiles = BlahUser.objects.get( gpa_filter, major_filter )
    

    Note that you can continue to use profiles as a regular queryset (as in this contrived example):

    seniors_matching_request_params = profiles.filter(status='senior')
    

    So, just use Q objects where you need to, then continue to operate on the queryset as normal .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.