﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
5420	Allow database API users to specify the fields to exclude in a SELECT statement	Adrian Holovaty	Malcolm Tredinnick	"This one will help people use their databases more efficiently.

The Django ORM should allow users to specify a list of field names to *exclude* from a {{{QuerySet}}}. If a user attempts to access one of those excluded fields on the resulting model instance, the field will be loaded lazily via a separate query.

This is useful when you know you absolutely will not need to use a particular field in your template, so there's no point in SELECTing that data. This saves memory, and it saves on bandwidth between the database server and the Web server.

Example:

{{{
#!python

class Person(models.Model):
    name = models.CharField(maxlength=32)
    age = models.IntegerField()
    hometown = models.CharField(maxlength=32)
    is_cool = models.BooleanField()

# My instinct is to call this hide(), but I'm sure there's a better name for it.
>>> p = Person.objects.hide('hometown', 'is_cool').get(name='John Lennon')
>>> p.id
3
>>> p.name
u'John Lennon'

# Does a query to get ""hometown"", because it was hidden from the QuerySet.
# 'SELECT hometown FROM person WHERE id=3;'
>>> p.hometown
u'Liverpool'

# Does a query to get ""is_cool"", because it was hidden from the QuerySet.
# 'SELECT is_cool FROM person WHERE id=3;'
>>> p.is_cool
True
}}}

In the case of lazily loaded fields, the lazy loading *only* applies to the particular field. E.g., when I accessed {{{p.hometown}}} in the above example, it did *not* also lazily load the rest of the hidden fields (""is_cool"").

We should also provide the inverse of {{{hide()}}} -- perhaps called {{{expose()}}}? -- which would take a list of field names to *include* rather than *exclude*. This would be an opt-in instead of an opt-out."		closed	Database layer (models, ORM)	dev		fixed	qs-rf	Manuel Saelices ferringb@… Marinho Brandão semente@… research@… youngj@… Erin Kelly Alexander Koshelev flosch@…	Accepted	1	1	0	1	0	0
