daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def update_or_create(self, model, defaults={}, **lookup):
  2.         try:
  3.             post, created = model.objects.get_or_create(defaults=defaults,
  4.                                                         **lookup)
  5.         except model.MultipleObjectsReturned:
  6.             # "safe" in this environment
  7.             return
  8.        
  9.         if not created:
  10.             fields = dict(defaults).update(lookup)
  11.             [setattr(model, f_name, f_value)
  12.                     for f_name, f_value in fields.items()]
  13.             model.save()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top