Skip to content

Instantly share code, notes, and snippets.

@vaibhav-jain
Created July 2, 2016 12:45
Show Gist options
  • Save vaibhav-jain/91f49e8252ad4860b419868f704bbcf7 to your computer and use it in GitHub Desktop.
Save vaibhav-jain/91f49e8252ad4860b419868f704bbcf7 to your computer and use it in GitHub Desktop.
Django Rest Framework (DRF) Custom Unique Together Message
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
class SomeSerializer(serializers.ModelSerializer):
"""
Demostrating How to Override DRF UniqueTogetherValidator Message
"""
class Meta:
model = Some
validators = [
serializers.UniqueTogetherValidator(
queryset=model.objects.all(),
fields=('field1', 'field2'),
message=_("Some custom message.")
)
]
@yk2408
Copy link

yk2408 commented Dec 27, 2018

This worked for me as well.
Thanks a lot.

@SimonAstani
Copy link

What if we want to check uniqueness based on lowercase character. can we do this in default validators or build own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment