4 ms·
Coding noob here. Can someone explain the problem with the `for foo in queryset` implementation? Is it that for loops are inherently inefficient? What would b
by philangist 13y ago
Coding noob here. Can someone explain the problem with the
`for foo in queryset`
implementation? Is it that for loops are inherently inefficient? What would be a better alternative?
- victorf 13y agoI don't see a problem with an O(n) algorithm to set some property on n objects.
- victorhooi 13y agoI think the issue is the call to save() (I assume this is meant to be outside the comma). Basically, it'll hit the database after each query.
- philangist 13y agoI originally thought it might be that too, but it seems to me like you'll have to hit the database n times for n queries no matter what. Unless Django has some builtin batch save functionality.
- victorhooi 13y agoHmm, there's bulk_create(), introduced in Django 1.4, to create multiple new objects in one DB call. However, I'm not aware of anything that would do the same to update properties.