Mimic queryset.update_or_create but using obj_update.

def obj_update_or_create(model, defaults=None, update_fields=UNSET, **kwargs):
    """
    Mimic queryset.update_or_create but using obj_update.
    """
    obj, created = model.objects.get_or_create(defaults=defaults, **kwargs)
    if created:
        logger.debug('CREATED %s %s',
                     model._meta.object_name,
                     obj.pk,
                     extra={'pk': obj.pk})
    else:
        obj_update(obj, defaults, update_fields=update_fields)
    return obj, created