Translate field names for UniqueTogetherValidator

Sorry to bother you.
It might be a good idea to translate field names for the UniqueTogetherValidator message.
This commit is contained in:
urbsny 2019-01-10 01:27:28 +09:00 committed by GitHub
parent e3bd4b9048
commit 0d78d46ebd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,7 +165,8 @@ class UniqueTogetherValidator(object):
value for field, value in attrs.items() if field in self.fields
]
if None not in checked_values and qs_exists(queryset):
field_names = ', '.join(self.fields)
from django.utils.translation import gettext
field_names = ', '.join([gettext(field) for field in self.fields])
message = self.message.format(field_names=field_names)
raise ValidationError(message, code='unique')