HEHE

JD Solanki <jdsolanki0...@gmail.com> 于2020年7月21日周二 下午7:11写道:

> Hi, I have been wondering doesn't DRF convert Django's ValidationError
> raised from `validate_unique` or from `clean` method of the model?
>
> I have ModelViewSet:
> ```python
> class UpvoteViewSet(ModelViewSet):
>     queryset = Upvote.objects.all()
>     serializer_class = UpvoteSerializer
> ```
>
> and I have added `validate_unique` method to model:
>
> ```python
>     def validate_unique(self, *args, **kwargs):
>
>         super().validate_unique(*args, **kwargs)
>         upvote_model = self.__class__
>
>         if upvote_model.objects.filter(upvoted_item=self.upvoted_item,
> upvoted_user=self.upvoted_user).exists():
>             raise ValidationError(['This user already upvoted this item.',
> ])
> ```
>
> The problem is `ValidationError` is from Django and if I use DRF's
> ValidationError then I get an error in Django Admin. So, what's happening.
> Does DRF handle this??
>
> --
> 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 django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/873ecf8a-ffd9-459b-b271-d78d05633684o%40googlegroups.com
> <https://groups.google.com/d/msgid/django-rest-framework/873ecf8a-ffd9-459b-b271-d78d05633684o%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAOAhtQzt10tD5TRfTmYUe9Cv9tzf47SFCqn71Zyc_tyo04qf6A%40mail.gmail.com.

Reply via email to