【发布时间】:2019-10-11 15:38:10
【问题描述】:
基本上我有一个使用我的用户模型“Writer”的自定义 UserChangeForm,我想将所有字段的默认值设置为数据库的当前值(或请求用户的值)。解决此问题的最佳方法是什么?
我尝试在表单中设置默认值,但是在 forms.py 中无法访问请求对象
表格...
class writerChangeForm(UserChangeForm):
class Meta:
model = Writer
fields = ('username', 'email', 'first_name', 'last_name', 'country')
country = CountryField().formfield()
widgets = {'country': CountrySelectWidget()}
景色...
class ProfileView(generic.CreateView):
form_class = writerChangeForm
template_name = 'diary/profile.html'
感谢您的任何意见!
【问题讨论】:
标签: django forms field default