That seems simple enough, but all Django Queries seems to be ‘SELECT *’
How do I build a query returning only a subset of fields ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
In Django 1.1 onwards, you can use
defer('col1', 'col2')to exclude columns from the query, oronly('col1', 'col2')to only get a specific set of columns. See the documentation.valuesdoes something slightly different – it only gets the columns you specify, but it returns a list of dictionaries rather than a set of model instances.