Hello again,

For anyone interested, more detailed version was sent to stackoverflow:
https://stackoverflow.com/questions/73231297/proper-way-to-return-erroneous-data-with-serializer-error

Kind regards,
Sencer HAMARAT



On Wed, Aug 3, 2022 at 7:58 AM Sencer Hamarat <[email protected]>
wrote:

> Hi,
>
> I found a way to customize error messages of the serializer by adding
> extra_kwargs into the serializer meta class.
>
> But, I'm wishing to render custom serializer errors with the incorrect
> data. For example:
>
> class CreateUserSerializer(serializer.ModelSerializer):
>     class Meta:
>         model = User
>         fields = ('first_name', 'last_name', 'is_active', 'email')
>
> def create_users(request):
>     ...
>     serialized_data = CreateUserSerializer(data=data, many=True)
>     if serialized_data.is_valid():
>         serialized_data.save()
>
> Say, afew of the user data has no email information.
> This will return error like:
>
> {"email":["This field may not be blank."], "email":["This field may not be
> blank."], ...}
>
> I want to add error related data or at least index number to error text
>
> Is there a way to do that?
>
> Kind regards,
> Sencer HAMARAT
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZhGm7Seqqas2WC1rwYNuZP18Vm-m65%2B70YGH2856%2BS-bg%40mail.gmail.com.

Reply via email to