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

  • SEARCH
  • Home
  • 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 455285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:21:19+00:00 2026-05-12T22:21:19+00:00

From the following code: dvdList = Dvd.objects.filter(title = someDvdTitle)[:10] for dvd in dvdList: result

  • 0

From the following code:

dvdList = Dvd.objects.filter(title = someDvdTitle)[:10]

for dvd in dvdList:
    result = "Title: "+dvd.title+" @ "+dvd.price+"."

When does Django do the lookup? Maybe it’s just paranoia, but it seems if I comment out the for loop, it returns a lot quicker. Is the first line setting up a filter and then the for loop executes it, or am I completely muddled up? What actually happens with those lines of code?

EDIT:

What would happen if I limited the objects.filter to ‘1000’ and then implemented a counter in the for loop that broke out of it after 10 iterations. Would that effectively only get 10 values or 1000?

  • 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-12T22:21:19+00:00Added an answer on May 12, 2026 at 10:21 pm

    Django querysets are evaluated lazily, so yes, the query won’t actually be executed until you try and get values out of it (as you’re doing in the for loop).

    From the docs:

    You can evaluate a QuerySet in the following ways:

    Iteration. A QuerySet is iterable, and
    it executes its database query the
    first time you iterate over it. For
    example, this will print the headline
    of all entries in the database:

    for e in Entry.objects.all():
        print e.headline
    

    …(snip)…

    See When Querysets are evaluated.

    Per your edit:

    If you limited the filter to 1000 and then implemented a counter in the for loop that broke out of it after 10 iterations, then you’d hit the database for all 1000 rows – Django has no way of knowing ahead of time exactly what you’re going to do with the Queryset – it just knows that you want some data out of it, so evaluates the query string it’s built up.

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

Sidebar

Related Questions

Does anyone know if its possible to use Bulk insert from following code: FORALL
I can not get the right result from the following code block: object ob
I didn't get the result I want from the following code: Private Sub tblView_SelectionChanged(ByVal
I'm not getting the result expect from the following code: #!/bin/bash cat /home/opmeitle/html/fiesta-one.html |
The title is the error I get from the following code: $(this).parent().slideUp(200, function ()
What does this line from the following code sample mean? synchronized (_surfaceHolder) { _panel.onDraw(c);
I'm not getting the result expect from the following code: #!/bash/perl use strict; use
What do I have to change from the following code to make the Storyboard
I have been trying to extract e-mail addresses from the following code for quite
How would I get returningResponse (into say, a NSString) from the following code: NSURLResponse*

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.