From 510b2d2a2ddd620aff0372fe1b85f2a8d5354a66 Mon Sep 17 00:00:00 2001 From: Dominik George <nik@naturalnet.de> Date: Fri, 23 Aug 2019 09:41:23 +0200 Subject: [PATCH] Work around limitation that model forms can only have editable fields. --- biscuit/apps/alsijil/forms.py | 15 ++++++++++++++- biscuit/apps/alsijil/models.py | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/biscuit/apps/alsijil/forms.py b/biscuit/apps/alsijil/forms.py index 877863eb3..51cdfe3d7 100644 --- a/biscuit/apps/alsijil/forms.py +++ b/biscuit/apps/alsijil/forms.py @@ -10,5 +10,18 @@ class LessonDocumentationForm(forms.ModelForm): fields = ['topic', 'homework'] +class PersonalNoteForm(forms.ModelForm): + class Meta: + model = PersonalNote + fields = ['person', 'absent', 'late', 'excused', 'remarks'] + + def __init__(self, *args, **kwargs): + super().__init__(*awrgs, **kwargs) + self.fields['person'].widget.attrs['readonly'] = True + + def clean_person(self): + return self.instance.person + + PersonalNoteFormSet = forms.modelformset_factory( - PersonalNote, fields=('person', 'absent', 'late', 'excused', 'remarks')) + PersonalNote, form=PersonalNoteForm) diff --git a/biscuit/apps/alsijil/models.py b/biscuit/apps/alsijil/models.py index 265d2e33d..5e9094d75 100644 --- a/biscuit/apps/alsijil/models.py +++ b/biscuit/apps/alsijil/models.py @@ -5,7 +5,7 @@ from biscuit.core.mixins import SchoolRelated class PersonalNote(SchoolRelated): - person = models.ForeignKey('core.Person', models.CASCADE, editable=False) + person = models.ForeignKey('core.Person', models.CASCADE) week = models.IntegerField() lesson_period = models.ForeignKey('chronos.LessonPeriod', models.CASCADE) -- GitLab