def _update_counter(model, field_name, filter_kwargs, increment=1):
 try:
  record = model.objects.filter(**filter_kwargs)
  affected = record.update(**{field_name: (F(field_name) + increment)})
  if (not affected):
   filter_kwargs[field_name] = increment
   model.objects.create(**filter_kwargs)
 except IntegrityError:
  logger.error('IntegrityError when updating analytics counter for %s', model)

def _update_counter ( model , field_name , filter_kwargs , increment = 1 ) : try : record = model . objects . filter ( ** filter_kwargs ) affected = record . update ( ** { field_name : ( F ( field_name ) + increment ) } ) if ( not affected ) : filter_kwargs [ field_name ] = increment model . objects . create ( ** filter_kwargs ) except IntegrityError : logger . error ( 'IntegrityError when updating analytics counter for %s' , model )
efficiently updates a counter field by a given increment .