def update_many(objects, fields=[], using="<STR_LIT:default>"):
if not objects:<EOL><INDENT>return<EOL><DEDENT>import django.db.models<EOL>from django.db import connections<EOL>from django.db import transaction<EOL>con = connections[using]<EOL>names = fields<EOL>meta = objects[<NUM_LIT:0>]._meta<EOL>fields = [f for f in meta.fields<EOL>if not isinstance(f, django.db.models.AutoField)<EOL>and (not names or f.name in names)]<EOL>if not fields:<EOL><INDENT>raise ValueError("<STR_LIT>" % names)<EOL><DEDENT>fields_with_pk = fields + [meta.pk]<EOL>parameters = []<EOL>for o in objects:<EOL><INDENT>parameters.append(tuple(f.get_db_prep_save(f.pre_save(o, True),<EOL>connection=con) for f in fields_with_pk))<EOL><DEDENT>table = meta.db_table<EOL>assignments = "<STR_LIT:U+002C>".join(("<STR_LIT>" % con.ops.quote_name(f.column))<EOL>for f in fields)<EOL>con.cursor().executemany("<STR_LIT>"<EOL>% (table, assignments,<EOL>con.ops.quote_name(meta.pk.column)),<EOL>parameters)<EOL>transaction.commit_unless_managed(using=using)<EOL>
Update list of Django objects in one SQL query, optionally only
    overwrite the given fields (as names, e.g. fields=["foo"]).
    Objects must be of the same Django model. Note that save is not
    called and signals on the model are not raised.

    Mostly from: http://people.iola.dk/olau/python/bulkops.py