正常复制一条model记录:

In [24]: obj = Product.objects.get(pk=6)                                                                                                                                                         
In [25]: obj.id = None                                                                                                                                                                           
In [26]: obj.save()                                                                                                                                                                              
In [27]: obj.id                                                                                                                                                                                  
Out[27]: 7


出现关联错误,可以用下面这种比较牛逼的方法:

from django.db.models import AutoField
def copy_model_instance(obj):
    """Create a copy of a model instance.
    M2M relationships are currently not handled, i.e. they are not
    copied.
    See also Django #4027.
    """
    initial = dict([(f.name, getattr(obj, f.name))
                    for f in obj._meta.fields
                    if not isinstance(f, AutoField) and
                       not f in obj._meta.parents.values()])
    return obj.__class__(**initial)

In [37]: obj=Product.objects.get(pk=5)                                                                                                                                                           
In [38]: obj=copy_model_instance(obj)                                                                                                                                                            
In [39]: obj.save()                                                                                                                                                                              
In [40]: obj.id                                                                                                                                                                                  
Out[40]: 6


参考地址:https://blog.elsdoerfer.name/2008/09/09/making-a-copy-of-a-model-instance/