On Wed, 2007-12-19 at 05:35 -0800, shabda wrote: > I have a QuerySet returned by a call like this > > foos = Foo.objects.filter(id__in = [1, 2, 3]) > > Now I want to update each of these elements' attributes to a specific > value. What I need to do is some thing like, > > for foo in foos: > foo.price = 0 > foo.save() > > But this would make as many database hits as elements in my QuerySet. > If I were using a raw sql I could have written some thing like > update foo set price = 0 whede id in (1, 2, 3) > with one database hit. How can I do the same in django, wichout > writing custom sql?
You can't. This is ticket #4260. I'm still working out the full API for it (I've spent a bit of time on it this evening, coincidentally). Don't be afraid to write custom SQL. Remember that Django's ORM is intentionally not designed to be a 100% replacement for SQL, since SQL already exists. So, from time to time, it's faster to just write the query. Regards, Malcolm -- If it walks out of your refrigerator, LET IT GO!! http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---