#NEWLINE# def update_many( objects , fields = [ ] , using = 'default' ) : #NEWLINE# #INDENT# 'Update list of Django objects in one SQL query, optionally only\n    overwrite the given fields (as names, e.g. fields=["foo"]).\n    Objects must be of the same Django model. Note that save is not\n    called and signals on the model are not raised.' #NEWLINE# if ( not objects ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# import django.db.models #NEWLINE# from django.db import connections #NEWLINE# con = connections [ using ] #NEWLINE# names = fields #NEWLINE# meta = objects [ 0 ] . _meta #NEWLINE# fields = [ f for f in meta . fields if ( ( not isinstance ( f , django . db . models . AutoField ) ) and ( ( not names ) or ( f . name in names ) ) ) ] #NEWLINE# if ( not fields ) : #NEWLINE# #INDENT# raise ValueError ( ( 'No fields to update, field names are %s.' % names ) ) #NEWLINE# #UNINDENT# fields_with_pk = ( fields + [ meta . pk ] ) #NEWLINE# parameters = [ ] #NEWLINE# for o in objects : #NEWLINE# #INDENT# parameters . append ( tuple ( ( f . get_db_prep_save ( f . pre_save ( o , True ) , connection = con ) for f in fields_with_pk ) ) ) #NEWLINE# #UNINDENT# table = meta . db_table #NEWLINE# assignments = ',' . join ( ( ( '%s=%%s' % con . ops . quote_name ( f . column ) ) for f in fields ) ) #NEWLINE# con . cursor ( ) . executemany ( ( 'update %s set %s where %s=%%s' % ( table , assignments , meta . pk . column ) ) , parameters )