instance = model.get_by(**kwargs)
if not instance:
instance = model(**kwargs)
+ return instance
+
+def update_or_create(model, get_by, update_with):
+ instance = model.get_by(**get_by)
+ if instance:
+ # set new values
+ for key,value in update_with.items():
+ setattr(instance, key, value)
+ else:
+ # create it
+ both = {}
+ both.update(get_by)
+ both.update(update_with)
+ instance = model(**both)
return instance
\ No newline at end of file