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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:05:53+00:00 2026-05-26T04:05:53+00:00

How can I query on the full name in Django? To clarify, I essentially

  • 0

How can I query on the full name in Django?

To clarify, I essentially want to do create a temporary column, combining first_name and last_name to give a fullname, then do a LIKE on that, like so:

select [fields] from Users where CONCAT(first_name, ' ', last_name) LIKE '%John Smith%";

The above query would return all users named John Smith. If possible I’d like to avoid using a raw SQL call.

The model I’m talking about specifically is the stock django.contrib.auth.models User model. Making changes to the model directly isn’t a problem.

For example, if a user was to search for ‘John Paul Smith’, it should match users with a first name of ‘John Paul’ and last name ‘Smith’, as well as users with first name ‘John’ and last name ‘Paul Smith’.

  • 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-26T04:05:53+00:00Added an answer on May 26, 2026 at 4:05 am

    Unless I’m missing something, you can use python to query your DB like so:

    from django.contrib.auth.models import User
    x = User.objects.filter(first_name='John', last_name='Smith') 
    

    Edit:
    To answer your question:

    If you need to return ‘John Paul Smith’ when the user searches for ‘John Smith’ then you can use ‘contains‘ which translates into a SQL LIKE. If you just need the capacity to store the name ‘John Paul’ put both names in the first_name column.

    User.objects.filter(first_name__contains='John', last_name__contains='Smith') 
    

    This translates to:

    SELECT * FROM USERS
    WHERE first_name LIKE'%John%' 
    AND last_name LIKE'%Smith%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
i want to recober all the users with blo in their full name, for
I have a customer table with two columns first_name and last_name . How can
I have these two database tables: locations id name users id location_id last_name first_name
I can query for the picture,location and privacy fields/connections of a users Facebook event
I am having trouble writing query so that I can query the content of
Is there any function in C on linux by which we can query MX
Whats query can be used to get the details of Indexes of any table?
How can I query Active Directory from SQL Server 2005?
How can I query git to find out which branches contain a given commit?

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.