def write_models(model, data, field=None):
 if hasattr(data, 'hashes'):
  data = hashes_data(data)
 written = []
 for hash_ in data:
  if field:
   if (field not in hash_):
    raise KeyError(('The "%s" field is required for all update operations' % field))
   model_kwargs = {field: hash_[field]}
   model_obj = model.objects.get(**model_kwargs)
   for (to_set, val) in hash_.items():
    setattr(model_obj, to_set, val)
   model_obj.save()
  else:
   model_obj = model.objects.create(**hash_)
  written.append(model_obj)
 reset_sequence(model)
 return written

def write_models ( model , data , field = None ) : if hasattr ( data , 'hashes' ) : data = hashes_data ( data ) written = [ ] for hash_ in data : if field : if ( field not in hash_ ) : raise KeyError ( ( 'The "%s" field is required for all update operations' % field ) ) model_kwargs = { field : hash_ [ field ] } model_obj = model . objects . get ( ** model_kwargs ) for ( to_set , val ) in hash_ . items ( ) : setattr ( model_obj , to_set , val ) model_obj . save ( ) else : model_obj = model . objects . create ( ** hash_ ) written . append ( model_obj ) reset_sequence ( model ) return written
create or update models for each data hash .