lcsavb / ac2

MIT License
0 stars 0 forks source link

CreatePatient(forms.ModelForm) not associating automatically Patient to Issuer #7

Open lcsavb opened 8 months ago

lcsavb commented 8 months ago

I had to write a custom save() method.

def save(self, commit=True): patient = super().save(commit=False) issuer_list = self.cleaned_data.get('issuer') if commit: patient.save()

The patient must be to the logged-in user and in its issuer list

        self.user.patients.add(patient)
        [patient.issuer.add(issuer) for issuer in issuer_list]
    return patient

It's needed a custom method anyway to associate the Patient to the logged user, YET the association with Issuer should be automatic.

It is working that way, but it shouldn' be necessary to explicitly write [patient.issuer.add(issuer) for issuer in issuer_list]