*我想使用forms.py中的request.session.get[] model choice字段填充 form.py文件
class AssetTagForm(ModelForm):
assets = forms.ModelChoiceField(widget=forms.Select(attrs={'class': 'form-control'}) ,queryset=Asset.objects.filter(branch = self.session['branch']))
class Meta:
model = AssetTag
fields = '__all__'
labels = {
'tag':'Asset Tag',
}
exclude = ['created_by',]
widgets = {
'branch':forms.CheckboxSelectMultiple(attrs={}),
'code':forms.TextInput(attrs={'class':'form-control', 'placeholder':'Code','readonly':'readonly'}),
'tag':forms.TextInput(attrs={'class':'form-control', 'placeholder':'Asset Tag'}),
'status':forms.Select(attrs={'class':'form-control'}),
}
字符串
我不知道form.py文件中request.session.get[]变量的用法
1条答案
按热度按时间hm2xizp91#
您可以在初始化表单时填充初始数据。
参考:https://docs.djangoproject.com/en/4.2/ref/forms/api/
字符串