I try using FBV (logic more easy to understand for me).
Maybe I should have used inlineformset_facory to deal with FK but for conception concerns patient is passed in context.
I faced many issues I've tried to solved but it is more "hack" and I would like to find a proper way to do the same:
empty_forms was submitted and create a record in database; normally, default formset behavior is not to submit empty formset I manage this case using condition form.cleaned_data != {}. It is maybe cause
I define unique_together in my model Traitement. But it seems this is not manage by Django in form validation. When submitting a form with duplicates, IntegrityError is raised. I manage this case using a try-catch bloc. I also tried to define a form validation with clean() method in TraitementForm but doesn't seems to works.
With traitement_create() code below, all errors can not be displayed at the same time: forma validation will be displayed but not the IntegretyError if any.
I have read many documentation and tutorial but could not find answer.
Don't know how I can post code here so I attached txt doc with part of my code.
Jérôme