(obj, changes=None)
return duplicate
Duplicates any object including m2m fields
    changes: any changes that should occur, example
    changes = (('fullname','name (copy)'), ('do not copy me', ''))
Duplicates any object including m2m fields
    changes: any changes that should occur, example
    changes = (('fullname','name (copy)'), ('do not copy me', ''))
Duplicates any object including m2m fields changes : any changes that should occur example changes = (( fullname name ( copy ) ) ( do not copy me ))
def duplicate(obj, changes=None):
    """ Duplicates any object including m2m fields
    changes: any changes that should occur, example
    changes = (('fullname','name (copy)'), ('do not copy me', ''))"""
    if not obj.pk:
        raise ValueError('Instance must be saved before it can be cloned.')
    duplicate = copy.copy(obj)
    duplicate.pk = None
    for change in changes:
        duplicate.__setattr__(change[0], change[1])
    duplicate.save()
    # trick to copy ManyToMany relations.
    for field in obj._meta.many_to_many:
        source = getattr(obj, field.attname)
        destination = getattr(duplicate, field.attname)
        for item in source.all():
            try:  # m2m, through fields will fail.
                destination.add(item)
            except:
                pass
    return duplicate
def duplicate ( obj , changes = None ) : if not obj . pk : raise ValueError ( 'Instance must be saved before it can be cloned.' ) duplicate = copy . copy ( obj ) duplicate . pk = None for change in changes : duplicate . __setattr__ ( change [ 0 ] , change [ 1 ] ) duplicate . save ( ) # trick to copy ManyToMany relations. for field in obj . _meta . many_to_many : source = getattr ( obj , field . attname ) destination = getattr ( duplicate , field . attname ) for item in source . all ( ) : try : # m2m, through fields will fail. destination . add ( item ) except : pass return duplicate