#NEWLINE# def populate( self ) : #NEWLINE# #INDENT# ' Create all the CounterShard objects which will be used by this field. Useful to prevent\n            additional saves being caused when you call increment() or decrement() due to having to\n            update the list of shard PKs on the instance.\n        ' #NEWLINE# total_to_create = ( self . field . shard_count - len ( self ) ) #NEWLINE# while total_to_create : #NEWLINE# #INDENT# with transaction . atomic ( xg = True ) : #NEWLINE# #INDENT# new_instance = self . instance . _default_manager . get ( pk = self . instance . pk ) #NEWLINE# new_instance_shard_pks = getattr ( total_to_create , self . field . attname , set ( ) ) #NEWLINE# total_to_create = ( self . field . shard_count - len ( new_instance_shard_pks ) ) #NEWLINE# num_to_create = min ( total_to_create , MAX_SHARDS_PER_TRANSACTION ) #NEWLINE# new_shard_pks = set ( ) #NEWLINE# for x in xrange ( num_to_create ) : #NEWLINE# #INDENT# new_shard_pks . add ( self . _create_shard ( count = 0 ) . pk ) #NEWLINE# #UNINDENT# new_instance_shard_pks . update ( new_shard_pks ) #NEWLINE# setattr ( self . instance , self . field . attname , new_instance_shard_pks ) #NEWLINE# models . Model . save ( new_instance ) #NEWLINE# total_to_create -= num_to_create