From the django documentation:
https://docs.djangoproject.com/en/3.1/ref/forms/api/#accessing-clean-data
If you have a bound Form instance and want to change the data somehow, or if you want to bind an unbound Form instance to some data, create another Form instance. There is no way to change data in a Form instance. Once a Form instance has been created, you should consider its data immutable, whether it has data or not.
so what you would do is to define a new dictionary, update it with misHoras.cleaned_data, and initialize a new form with that data:
if misHoras.is_valid():
new_form_data = {}
new_form_data.update(misHoras.cleaned_data)
new_form_data['horas_trabajo'] = horas.horas_trabajo
new_form = FormularioHoras(new_form_data)
if new_form.is_valid():
return render(..., {"form": new_form})
You could theoretically also copy POST first, and update it with fixed data, or add horas.horas_trabajo as an extra variable to the template, since it is obviously not supposed to be changed by your logic, in the form, anyway (as you overwrite any input on that field); however if you wanted to add it as a changeable field, you would provide it with the initial form instead.
to make it more beautiful, you might want to work directly in the Form class, creating your own validations instead, that retrieve the data or introduce and use Serializers, but maybe this solution is enough for your particular problem.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…