【问题标题】:Django Generic Views disabling fieldsDjango通用视图禁用字段
【发布时间】:2018-04-19 13:38:19
【问题描述】:

一个Modelform由两个字段组成,不是从前端插入,而是在编码级别设置数据。一个是 Case No 字段,并且从序列更新值,第二个是映射到用户用于日志目的的外键字段。

self.fields['last_modifieduser'].queryset = Profile.objects.filter(user=profile.user,widget=forms.HiddenInput())

我将这两个字段分别设为只读和禁用。 每当进行表单验证时,都会有两个字段出错。

请帮我解决这个问题。

【问题讨论】:

  • 请显示完整视图。

标签: django django-forms


【解决方案1】:

语法错误

修改代码

self.fields['last_modifieduser'].queryset = Profile.objects.filter(user=profile.user,widget=forms.HiddenInput())

self.fields['last_modifieduser'].queryset = Profile.objects.filter(user=profile.user)
self.fields['last_modifieduser'].widget = forms.HiddenInput()

未测试。但是,它会起作用。

【讨论】:

  • 我也做了同样的事情,但由于该字段隐藏在表单选择下拉列表中,我设置的选项值未选择。所以 form.error 正在生效。
猜你喜欢
  • 2011-06-28
  • 2021-01-22
  • 1970-01-01
  • 1970-01-01
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-04
相关资源
最近更新 更多