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 6935805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:09:04+00:00 2026-05-27T12:09:04+00:00

I have this a = ‘Something’: False I want it to be this a

  • 0

I have this

a = "'Something': False"

I want it to be this

a = 'Something': False

How do I do it? I can strip things within the double quotation marks, but not the quotation marks itself. Have researched, cant find. I have mind block at moment. Sorry

Im trying to do this:

query_results = UserProfile.objects.filter(Location: location, Gender: gender).extra(select={'rank': a > 0}, order_by=['-rank'])

where Location = Someplace and Gender = Male or Female.

But what about when i did not want a specific gender or location. The only thing i could think of to do was to do

Location__isnull:False,  Gender__isnull:False

But i cant have both

Location:location, Location__isnull:False.

Thus i have to have the location argument as a variable.

How could i then do this. The information referring to Location and gender is coming from a request.GET

I cant post my code as i keep deleting and changing spaghetti to try make something edible.

  • 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-27T12:09:04+00:00Added an answer on May 27, 2026 at 12:09 pm

    For what you’re trying to do, the easiest way is to build up a dictionary of the arguments you want to supply, then pass them to the filter() call. Here’s some non-working sample code that might get you heading in the right direction.

    arguments = {}
    if location is not None:
        arguments['Location'] = location
    else:
        arguments['Location__isnull'] = False
    
    if gender is not None:
        arguments['Gender'] = gender
    else:
        arguments['Gender__isnull'] = False
    
    query_results = UserProfile.objects.filter(**arguments)
    

    It’s not clear from your question whether or not you really need to search these for records which are not null. An empty .filter() would return all the records just as if you’d called .all(), and if you use the pattern I’ve suggested, you could omit all the else clauses and just feed filter(**arguments) an empty dictionary.

    In other words, you only need to specify the query terms you really require, and do that by adding them to the arguments dictionary. Then you call filter with **arguments. The ** is a special Python syntax that says “take all the key/value pairs in this dictionary and turn them into keyword arguments for this function.”

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

Sidebar

Related Questions

I have this code in jQuery, that I want to reimplement with the prototype
I have this setup where in my development copy I can commit changes on
I have this code but it doesn't work! public class Trial { public static
I have this div which acts a lens in zooming of the image. But
Have this <a href=#>something</a> and then I handle it in Jquery code. This displays
Have this upload script, and it works. But I would like to add a
have this html: <div id=editable contentEditable=true > <span contentEditable=false >Text to delete</span> </div> need
I have this script: JsFiddle If you type something you will see Google suggestions.
I have this particular scenario, which is simple really, but I don't see (so
I have this code and can't figure out what seems to be the problem:

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.