Wenn ich das richtig sehe, wird
nicht erreicht, jedenfalls nicht, wenn nur ein Wert geändert wird.if profil_form.is_valid():
view:
Code: Alles auswählen
def profil_lehrer(req):
lehrer = Profil.objects.get(user=req.user)
if req.method == 'POST':
profil_form = Lehrer_Aendern_Form(req.POST)
if profil_form.is_valid():
profil_form.save()
return redirect('index')
else:
profil_form = Lehrer_Aendern_Form(instance=lehrer,)
context = {'profil_form': profil_form, 'titel': "Profil"}
return render(req, 'profil/profil_lehrer.html', context)
Code: Alles auswählen
class Lehrer_Aendern_Form(forms.ModelForm):
class Meta:
model = Profil
fields = ['vorname', 'nachname', 'ort', 'schule', 'jg', 'kurs', 'stufe']
Code: Alles auswählen
{% extends 'auswahl.html' %}
{% block content %}
<body>
<p>{{lehrer}}</p>
<form>
<table>
<form action="/profil_lehrer/" method="POST">
{% csrf_token %}
{{profil_form.as_table}}
</table>
<button type="submit">ändern</button>
</form>
</body>
{% endblock %}