sql - eliminating unnecessary database hits in django -
I want to minimize the actual database hit while working in the deogeity, so I decided to skip this problem for this artificial example is constructed. The model looks like this:
class car (models.Model): name = models.CharField (max_length = 10) user = models.ForeignKey (user)
In my opinion, I want to do something like this: >
def cartest (requests): cars = car._default_manager.filter (user__username__exact = 'michael') [: 5] first_car_name = cars [0] .name another_car = car [1] Httppacement (lane (connection.unces)) back
Then I want to select 5 entries from the database, do something already, then Do something with the other (remember this is an artificial Example).
Ah, understood this ... it achieves the desired effect Instead of being duplicated (or on the calling list (queries), the query was subscribing to the client. Once only hits the database:
def cartest (requested): cars = list (Car) ._default_manager.filter (user__username__exact = 'michael') [: 5]) first_car_name = car [0] another_car = car [1] back HTTPPRESSpace (lane (connection.unces))
Comments
Post a Comment