From: Guillaume Pellerin Date: Wed, 3 Feb 2016 17:45:40 +0000 (+0100) Subject: try to fix initial data X-Git-Tag: 1.1~160 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=27de961f23a37dd91510c411d5c0d7604ed2137d;p=teleforma.git try to fix initial data --- diff --git a/teleforma/forms.py b/teleforma/forms.py index ac1f1b9a..9d6a52c5 100644 --- a/teleforma/forms.py +++ b/teleforma/forms.py @@ -34,6 +34,15 @@ RegistrationForm.base_fields.update(ProfileForm.base_fields) class StudentForm(ModelForm): + + def has_changed(self): + """ + Overriding this, as the initial data passed to the form does not get noticed, + and so does not get saved, unless it actually changes + """ + changed_data = super(ModelForm, self).has_changed() + return bool(self.initial or changed_data) + class Meta: model = Student exclude = ['user', 'trainings', 'options'] @@ -65,7 +74,3 @@ class StudentInline(InlineFormSet): fields = ['iej', 'period', 'procedure', 'written_speciality', 'oral_speciality', 'oral_1', ] - def get_initial(self): - initial = super(StudentInline, self).get_initial() - initial['procedure'] = Course.objects.filter(title__contains='civil') - return initial diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index 9a89fe9f..c804b6c5 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -411,6 +411,13 @@ class UserAddView(CreateWithInlinesView): user.save() return super(UserAddView, self).forms_valid(form, inlines) + #def construct_inlines(self): + #Filtra el socio de negocio del detalle por tipo=Proveedor (Aseguradora) + # inlines = super(CreateWithInlinesView, self).construct_inlines() + # student_inline = inlines[1] + # student_inline.form.base_fields['procedure'].queryset = Course.objects.filter(title__contains='civil') + # return inlines + class UserCompleteView(TemplateView):