Hi,

On Tue, Dec 04, 2007 at 10:18:11AM -0600, Adrian Holovaty wrote:
> On Dec 4, 2007 12:57 AM, Gary Wilson <[EMAIL PROTECTED]> wrote:
> > But what would the situation be with a new limit() method...
> >
> > objects = MyModel.objects.filter(site=1)
> > first_one = objects.limit(1)
> > do_something_special(first_one)
> > return render_to_response('t.html', {'objects': objects, 'first': 
> > first_one})
> >
> > If limit() returns a new QuerySet, you're still going to have two queries.
> 
> No -- I guess I didn't explain myself well enough. In this case, I
> wouldn't use limit(). I have two goals:
> 
>     * Retrieve all objects in the table.
>     * Do something special with the first one (once the whole list has
> been retrieved).
> 
> The ideal API would look like this, and it would only run a single query:
> 
>     objects = MyModel.objects.filter(site=1)
>     first_one = objects[0]

Isn't that sort of wanting it both ways -- wanting querysets to be both lazy and
not?  Surely if the caller wants the objects fetched *now*, he should have to
indicate that, right?  Is this not a reasonable way to do that?

objects = list(MyModel.objects.filter(site=1))
first_one = objects[0]

Maybe another method would make that read nicer:

objects = MyModel.objects.filter(site=1).fetch()
first_one = objects[0]

-Forest
-- 
Forest Bond
http://www.alittletooquiet.net

Attachment: signature.asc
Description: Digital signature

Reply via email to