Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django模型检测用户是否试图更改字段_Django - Fatal编程技术网

django模型检测用户是否试图更改字段

django模型检测用户是否试图更改字段,django,Django,我正在保存模型,需要检测用户是否试图更改字段并显示错误: def save(self, *args, **kwargs): if self.status is being changed: error you cannot do that! 如何做到这一点是Django看看软件包是否能帮助您,引用文档: (ve)$ ./manage.py shell >>> from testing_app.models import TestModel

我正在保存模型,需要检测用户是否试图更改字段并显示错误:

 def save(self, *args, **kwargs):

     if self.status is being changed:
           error you cannot do that!
如何做到这一点是Django

看看软件包是否能帮助您,引用文档:

(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()
{}
>>>
另见:

希望对您有所帮助。

看看软件包是否能帮助您,引用文档:

(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()
{}
>>>
另见:

希望有帮助