I am new in django .ı post form but ı want to change form fields value , bu it cant. how can ı change my form fields value after the post.
def add_strateji(request):
form=StratejiForm
if request.method=="POST":
form=StratejiForm(request.POST)
form.fields['product_id']="value" \\ this is problem ı want constatant value for this fileds
if form.is_valid():
form.save()
return HttpResponseRedirect('list_amaclar')
form=StratejiForm
return render(request,'plans/add_strateji.html',{'form':form})
Is the form a regular form or a model form?
If it’s a regular form, then you don’t modify the form - you modify the models that you are creating from the data submitted in the form.
If it’s a model form, see The save() method, particularly where it’s talking about using the commit=False
parameter.
In either case, you also should read Working with forms | Django documentation | Django and the complete page at Creating forms from models | Django documentation | Django
It’s important that you understand the differences between the models and the form that is being built from a model.
Side note: When posting code here, enclose the complete block of code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.
it s modal form.
thank you for your answer
It helps me a lot.