Django formset: unicity constraint pass form_valid()

14 views
Skip to first unread message

Jérôme Le Carrou

unread,
Jun 5, 2023, 6:45:29 AM6/5/23
to Django users
Hi,

I've post my issue on Stackoverflow and do not have any ansewer so far.
Hope some Django dev could me here ;)

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:

  1. 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

  2. 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.

  3. 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

django_google_group.txt

Paul Haguet

unread,
Jun 6, 2023, 3:13:31 PM6/6/23
to Django users
Hello I doesn't understand what you want to do?

Je ne comprends pas ce que tu veux faire peut être je peux aider... Est-ce que tu peux juste donner l'obectif?
Reply all
Reply to author
Forward
0 new messages