From 82e81c602a795aeeb4e883b4f46a64c69e363a30 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 4 May 2021 23:52:26 +0200 Subject: [PATCH] =?UTF-8?q?Zprovozn=C4=9Bno=20vlo=C5=BEen=C3=AD=20=C5=99e?= =?UTF-8?q?=C5=A1en=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/forms.py | 6 +++--- seminar/views/views_all.py | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/seminar/forms.py b/seminar/forms.py index 44fae680..614d9aa3 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -274,9 +274,9 @@ class VlozReseniForm(forms.Form): #TODO body do cisla #TODO prilohy - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - #self.fields['favorite_color'] = forms.ChoiceField(choices=[(color.id, color.name) for color in Resitel.objects.all()]) + ##def __init__(self, *args, **kwargs): + ## super().__init__(*args, **kwargs) + ## #self.fields['favorite_color'] = forms.ChoiceField(choices=[(color.id, color.name) for color in Resitel.objects.all()]) class NahrajReseniForm(forms.ModelForm): class Meta: diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index c074f4b6..5c51c517 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -1026,7 +1026,20 @@ class ResitelView(LoginRequiredMixin,generic.DetailView): class AddSolutionView(LoginRequiredMixin, FormView): template_name = 'seminar/org/vloz_reseni.html' form_class = f.VlozReseniForm - success_url = '/' + + def form_valid(self, form): + data = form.cleaned_data + nove_reseni = m.Reseni.objects.create( + cas_doruceni=data['cas_doruceni'], + forma=data['forma'], + poznamka=data['poznamka'], + ) + nove_reseni.resitele.add(data['resitel']) + nove_reseni.problem.add(data['problem']) + nove_reseni.save() + # Chtěl jsem, aby bylo vidět, že se to uložilo, tak přesměrovávám na profil. + return redirect(reverse('profil')) + class NahrajReseniView(LoginRequiredMixin, CreateView): model = s.Reseni