Hi out there,
my understanding of Django and Python is growing day to day but still very small I’,m afraid.
So maybe someone can give me a hint to solve THIS kind of Probelm:
I have several Forms in my Project. I#m on a good way on dealing with forms up to now but encountered an interesting probelm:
Some of the forms are not only used to save data into database but also to ALTER the data. Therefore ich act like this in views (for example):
...
id_alter = request.POST['alterEmployment']
formdata = Employments.objects.get(id=id_alter)
form = EmploymentsForm(instance=formdata)
...
so i get a prefilled form with the stored data which i like to change.
BUT i have a Problem with the drop-down fields in the form.
If I want them properly prefilled, I have to go like
...
work_time_model = forms.ModelChoiceField(queryset=ArbeitszeitModell.objects.
values_list('arbeitszeitmodell', flat=True),
...
in forms.py, but then I get an error message upon save command like: “This is no valid choice”
if i use
...
work_time_model = forms.ModelChoiceField(queryset=ArbeitszeitModell.objects.all(),
...
i can save the from with new data but get no proper prefill…