2013-06-03 70 views

回答

1

看看django-dirtyfields包可以幫助你,引自文檔:

(ve)$ ./manage.py shell 
>>> from testing_app.models import TestModel 
>>> tm = TestModel(boolean=True,characters="testing") 
>>> tm.save() 
>>> tm.is_dirty() 
False 
>>> tm.get_dirty_fields() 
{} 
>>> tm.boolean = False 
>>> tm.is_dirty() 
True 
>>> tm.get_dirty_fields() 
{'boolean': True} 
>>> tm.characters = "have changed" 
>>> tm.is_dirty() 
True 
>>> tm.get_dirty_fields() 
{'boolean': True, 'characters': 'testing'} 
>>> tm.save() 
>>> tm.is_dirty() 
False 
>>> tm.get_dirty_fields() 
{} 
>>> 

另見:

希望有所幫助。

相關問題