tags:

views:

89

answers:

2

That seems simple enough, but all Django Queries seems to be 'SELECT *'

How do I build a query returning only a subset of fields ?

A: 

Append a .values("column1", "column2", ...) to your query

Ian Clelland
+4  A: 

In Django 1.1 onwards, you can use defer('col1', 'col2') to exclude columns from the query, or only('col1', 'col2') to only get a specific set of columns. See the documentation.

values does something slightly different - it only gets the columns you specify, but it returns a list of dictionaries rather than a set of model instances.

Daniel Roseman
Thanks, both have their usage.
PhilGo20