I noticed that I do not know if this is a real problem, or I am doing the wrong design.
I have a model:
class A(Model): name = CharField(unique=True, max_length=255)
and the model form associated with A, this modelform has a clean_name () method that checks if this field is unique in db (ignore the fact that modelforms already do this by default, I indicate that for example here).
In the view, if I do
o = form.save(commit=False) # xyz o.save()
and in #xyz I have another client that inserts an object A with the same value of the name field, o.save() Integrityerror exception, correctly preventing the duplicate entry from being inserted.
What do I need to know how to handle these cases, should I wrap this o.save() with a try / except block and fill in the error field in the form that determines the choice of another name value?
This is a fairly common case that should happen to everyone, and this decision is terrible, so I think I'm doing something terribly wrong.
source share