简体   繁体   English

是否可以获取Django的“ changed_data”列表中包含的项的值?

[英]Is it possible to get the value of an item contained in Django's “changed_data” list?

I have the following code in my Django application: 我的Django应用程序中包含以下代码:

if 'book' in authorForm.changed_data:
   #Do something here...

I realize Django can tell me which values have changed in my form by utilizing the "changed_data" list object, but I'd like to know the new values of the fields that have changed. 我意识到Django可以利用“ changed_data”列表对象告诉我表单中哪些值已更改,但是我想知道已更改字段的新值。

Any thoughts? 有什么想法吗?

Hmm... Try this: 嗯...试试这个:

if authorForm.is_valid() and 'book' in authorForm.changed_data:
    new_value = authorForm.cleaned_data['book']

我最初的问题的简短答案是“否”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Django中,如何使用列表项的String值获取对象变量的值? - In Django, how do I use a list item's String value to get an object's variable's value? 有没有办法通过知道当前项目的值来获取列表中的下一个项目? - Is there a way to get the next item in a list by knowing the current item's value? 检查项目是否包含在ManyToManyField(django)中 - Checking if an item is contained in a ManyToManyField (django) 是否可以从 django 的下拉列表中的选项中获取值? - Is it possible to get the value from an option in the drop down list in django? 如果它包含在另一个字符串列中,则从列表中获取字符串 - get string from list if it's contained in another string column 检查一个列表项是否包含在另一个列表中 - Checking if a list item is contained in another list 如果未包含在另一个列表中,则从数据框中的列表项中删除元素的优雅方法 - Elegant way to remove elements from list item in data frame if not contained in another list 如何在 django 中获取列表项作为 url 参数 - How to get the list item as url parameter in django Django:在QuerySet /词典中获取项目的固定值 - Django: Get flat value for an item in a QuerySet / dictionary 是否可以创建一个列表,其中的类型不能更改,但值本身可以? - Is it possible to create a list where types in it cannot be changed, but the value itself can?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM