def copy_obj(from_obj, to_obj, check_primary_key=False, check_related=False,
    exclude=[], copy_related_id=False, check_many_to_many=False):
    """
    モデルインスタンスのフィールドの内容をコピーする
    """
    for field in from_obj._meta.fields:
        if field.primary_key and not check_primary_key:
            continue
        if field.remote_field and not check_related:
            continue
        if field.name in exclude:
            continue
        if field.remote_field and copy_related_id:
            v = getattr(from_obj, field.name + '_id')
            setattr(to_obj, field.name + '_id', v)
        else:
            v = getattr(from_obj, field.name)
            setattr(to_obj, field.name, v)
    if check_many_to_many:
        to_obj.save()
        for field in from_obj._meta.many_to_many:
            if field.name in exclude:
                continue
            m1 = getattr(from_obj, field.name)
            m2 = getattr(to_obj, field.name)
            ids1 = list(m1.values_list('id', flat=True))
            ids2 = list(m2.values_list('id', flat=True))
            if len(ids1) == len(ids2) == len(set(ids1 + ids2)):
                continue
            m2.clear()
            m2_model = m2.model
            for obj in m1.all():
                m2.add(m2_model.objects.get(pk=obj.pk))
