from copy import deepcopy


def clone(obj):
    """
    Clone a database object.
    :param obj: Original object to be cloned
    :return: New, saved object. New object is identical to old *except* for id and pk
    Note that id and pk are often the same but can differ when using abstract models or model inheritance.
    """
    # Need deepcopy here so that obj become different from c.
    # If we use normal assignment, obj = c, when we change c, obj changes too, and that leads to unexpected behavior.
    c = deepcopy(obj)
    c.id = None
    c.pk = None
    c.save()
    return c