如何在 ModelForm 中提供初始值的问题得到了很好的回答: Overriding initial value in ModelForm
但是在模型创建后我如何填充一个值呢?或者我将如何更正此代码?
class Entry_form(forms.ModelForm):
class Meta:
model = models.Entry
exclude = ('')
:
def entry_add(request, pk):
form = Entry_form
selected_text = request.GET.get('selected_text', '')
form.fields['title'].initial = 'Test: ' + selected_text
return render(request, 'entry_add,{'form': form})