我正在使用SessionWizardView的done()方法来更新我的数据库中的两个计数器。我想将两个计数器字段的值打印到我的日志文件中。
如何访问和记录survey_wizard_count
和total_max_counter
的价值?
def done(self, form_list, **kwargs):
survey_counter = Counter.objects.get_or_create(survey_wizard_type = 'survey_wizard_one')[0]
survey_counter.survey_wizard_count = F('survey_wizard_count') + 1
survey_counter.total_max_counter = F('total_max_counter') + 1
survey_counter.save()
logger.debug('This is your survey_wizard_count = %s', ????????????????)
logger.debug('This is your total_max_counter = %s', ????????????????)
for form in form_list:
form.save()
return render(self.request, 'Return_to_AMT.html', {
'form_data': [form.cleaned_data for form in form_list],
})
由于
答案 0 :(得分:1)
这里没有理由使用F对象。这些在直接执行update
查询时很有用,但是在这里你已经有了这个对象。只需参考值:
survey_counter.survey_wizard_count += 1
survey_counter.total_max_counter += 1
survey_counter.save()
现在您可以直接记录值:
logger.debug('This is your survey_wizard_count = %s', survey_counter.survey_wizard_count)
答案 1 :(得分:0)
您可以尝试:
logger.debug("This is your survey_wizard_count is: " + survey_counter.survey_wizard_count)