Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
-
Example Model
Sample error response for violation |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 3 comments 1 reply
-
Yes, I encountered this issue as well. When the serializer gathers constraints from the model, it doesn’t account for the fact that a constraint might include a custom error message. Additionally, the |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi! I face to the same issue. |
BetaWas this translation helpful?Give feedback.
All reactions
👎 1
-
guys, any news? short workarounds? |
BetaWas this translation helpful?Give feedback.
All reactions
-
I created a custom validator by subclassing classCustomUniqueTogetherValidator(UniqueTogetherValidator):def__call__(self,attrs,serializer):self.enforce_required_fields(attrs,serializer)try:super().__call__(attrs,serializer)exceptserializers.ValidationErrorasexc: [msg]=exc.detailraiseserializers.ValidationError(str(msg),code="custom_unique_constraint" )fromexcclassMySerializer(serializers.ModelSerializer):classMeta:model=MyModelfields="__all__"validators= [CustomUniqueTogetherValidator(queryset=MyModel.objects.filter(...).all(),fields=["field1","field2"],message="My custom message." ), ] If an issue is opened based on this discussion, I’d be happy to submit a PR with a fix. |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #9350 on March 28, 2024 10:16.