【问题标题】:Django TypeError: 'int' object is not callable when trying save data in modelsDjango TypeError:尝试在模型中保存数据时无法调用“int”对象
【发布时间】:2018-02-01 09:37:34
【问题描述】:

我正在尝试将问题带入我的模型的值不保存,执行此操作的函数如下所列,模型中的 no_value 字段是 IntegerField,默认值为 0。

def _no_value():
    questions = Question.objects.all()
    for question in questions:
        regex = re.compile('(__[_]*)')
        no_value = (regex.findall(question.question))
        if no_value:
            value = len(no_value)
            question.no_value(value)
            question.save()

请告诉我如何解决这个错误。

【问题讨论】:

  • question.no_value = value

标签: python django python-3.x django-models django-views


【解决方案1】:

question.no_value 是您的数据库查询中的一个对象(questions = Question.objects.all() ) 如果要更新 no_value 的值,请使用下面的 sn-p。

question.no_value = value
question.save()

或者如果是更新

question.no_value = question.no_value + value
question.save()

【讨论】:

    猜你喜欢
    • 2021-08-05
    • 1970-01-01
    • 2021-12-17
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    相关资源
    最近更新 更多