peewee 對象clone函數

起因:
我需要得到peewee對象的clone對象,寫個簡單的小程序

def clone(instance):
    obj = instance.__class__()
    # print a._meta.fields
    data = getattr(instance, "_data")
    for key in a._meta.fields:
    # print key
        if key != 'id':
            setattr(obj, key, data[key])
    return obj
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章