One way to solve this problem, is to have that model field not unique in
the models. And enforce the uniqueness through code.
So, you would write a validate_fieldname(self, value) method in the
serializer to make sure that the field in question is unique and not as
required
Hope this helps.


Regards,
Chetan Ganji
+91-900-483-4183
[email protected]
http://ryucoder.in


<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
I’m
protected online with Avast Free Antivirus. Get it here — it’s free forever.
<https://www.avast.com/en-in/recommend?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=default3&tag=7ce9710f-d0c2-48a2-a0ba-76107578348e>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, Mar 14, 2019 at 4:17 PM kumar deepak <[email protected]> wrote:

> If I have a default serializer using a django model with one of the field
> being unique, data will always have is_valid() False.
> I may be using this data for update (not create), so making this invalid
> does not make sense.
>
> Ideally if id (or primary key is provided), it should mean that the data
> will be used for update and unique validator should not be run.
> Currently I can not use model->serialized_data->model save, is_valid fails
> in this case.
>
> I must be missing something obvious.
>
> validators = [] also did not work, unique validation still happens. How
> can I override it or switch it off.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to