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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:52:07+00:00 2026-05-31T13:52:07+00:00

I wanted to know is there anything equivalent to: select columnname from tablename Like

  • 0

I wanted to know is there anything equivalent to:

select columnname from tablename

Like Django tutorial says:

Entry.objects.filter(condition)

fetches all the objects with the given condition. It is like:

select * from Entry where condition

But I want to make a list of only one column [which in my case is a foreign key]. Found that:

Entry.objects.values_list('column_name', flat=True).filter(condition)

does the same. But in my case the column is a foreign key, and this query loses the property of a foreign key. It’s just storing the values. I am not able to make the look-up calls.

  • 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-31T13:52:08+00:00Added an answer on May 31, 2026 at 1:52 pm

    Of course, values and values_list will retrieve the raw values from the database. Django can’t work its “magic” on a model which means you don’t get to traverse relationships because you’re stuck with the id the foreign key is pointing towards, rather than the ForeignKey field.

    If you need to filters those values, you could do the following (assuming column_name is a ForeignKey pointing to MyModel):

    ids = Entry.objects.values_list('column_name', flat=True).filter(...)
    my_models = MyModel.objects.filter(pk__in=set(ids))
    

    Here’s a documentation for values_list()

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

Sidebar

Related Questions

I just wanted to know if there's anything built into the .net framework where
I wanted to know if there is way to log the mysql queries in
Just wanted to know if there is a big chance to inject SQL While
I wanted to know if there's a way I can bind an Asp.net Ajax
I wanted to know if there is any way to synchronize (or exchanging files)
I just wanted to know if there is a way on how to remove
I'm playing around with html client side storage and wanted to know if there
I know there are non-standard frameworks such as commons-validator, and hibernate validator. I wanted
Wanted to know if someone had a suggestion on code or maybe there's a
I just wanted to know, if there is any technique to insert values into

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.