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

  • Home
  • SEARCH
  • 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 197889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:53:30+00:00 2026-05-11T16:53:30+00:00

I have first_name , last_name & alias (optional) which I need to search for.

  • 0

I have first_name, last_name & alias (optional) which I need to search for. So, I need a query to give me all the names that have an alias set.

Only if I could do:

Name.objects.filter(alias!="")

So, what is the equivalent to the above?

  • 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-11T16:53:30+00:00Added an answer on May 11, 2026 at 4:53 pm

    You could do this:

    Name.objects.exclude(alias__isnull=True)
    

    If you need to exclude null values and empty strings, the preferred way to do so is to chain together the conditions like so:

    Name.objects.exclude(alias__isnull=True).exclude(alias__exact='')
    

    Chaining these methods together basically checks each condition independently: in the above example, we exclude rows where alias is either null or an empty string, so you get all Name objects that have a not-null, not-empty alias field. The generated SQL would look something like:

    SELECT * FROM Name WHERE alias IS NOT NULL AND alias != ""
    

    You can also pass multiple arguments to a single call to exclude, which would ensure that only objects that meet every condition get excluded:

    Name.objects.exclude(some_field=True, other_field=True)
    

    Here, rows in which some_field and other_field are true get excluded, so we get all rows where both fields are not true. The generated SQL code would look a little like this:

    SELECT * FROM Name WHERE NOT (some_field = TRUE AND other_field = TRUE)
    

    Alternatively, if your logic is more complex than that, you could use Django’s Q objects:

    from django.db.models import Q
    Name.objects.exclude(Q(alias__isnull=True) | Q(alias__exact=''))
    

    For more info see this page and this page in the Django docs.

    As an aside: My SQL examples are just an analogy–the actual generated SQL code will probably look different. You’ll get a deeper understanding of how Django queries work by actually looking at the SQL they generate.

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

Sidebar

Ask A Question

Stats

  • Questions 176k
  • Answers 176k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You use .Net transactions, not ADO transactions. ADO is aware… May 12, 2026 at 3:14 pm
  • Editorial Team
    Editorial Team added an answer for(vector<int>::iterator iter = sudokuBoard[i][j].possibleIntegers.begin(); iter!= sudokuBoard[i][j].possibleIntegers.end();) You don't seem to… May 12, 2026 at 3:14 pm
  • Editorial Team
    Editorial Team added an answer Having made your code a bit more Pythonic (but without… May 12, 2026 at 3:14 pm

Related Questions

I'd like to create a list of an anonymous type, for example: Dim lineItem
I have a field in my form labeled Name that will contain both the
I have the following scenario: 1) A phone book table 2) Multiple ways of
I have been tasked with creating a reusable process for our Finance Dept to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.