Answer the question
In order to leave comments, you need to log in
How to edit an object with a unique field using a form?
The problem appeared out of nowhere. It is necessary to implement the object editing function through the form, to which the instance is passed to fill in the fields. Django complains that the form is not valid and refuses to accept it. How to make the form pass validation if it is editing, and when creating a new object, it also checks for uniqueness? I just don't really want to remove form.is_valid() somehow.
Answer the question
In order to leave comments, you need to log in
Make sure that when the form is submitted, the pk is also submitted. Django distinguishes between creating and editing based on it. If pk is not passed on submission, Django considers this to be the creation of a new object, and then you will already get an error due to a non-unique field.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question