From b4d138002fa79a8c94791e6aa184a9927647ee18 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 4 Oct 2016 13:25:44 +0200 Subject: [PATCH] Replace ignore_case arg with more explicit lookup arg in UniqueValidator --- rest_framework/validators.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rest_framework/validators.py b/rest_framework/validators.py index d495139a8..84af0b9d5 100644 --- a/rest_framework/validators.py +++ b/rest_framework/validators.py @@ -42,11 +42,11 @@ class UniqueValidator(object): """ message = _('This field must be unique.') - def __init__(self, queryset, message=None, ignore_case=True): + def __init__(self, queryset, message=None, lookup='exact'): self.queryset = queryset self.serializer_field = None self.message = message or self.message - self.ignore_case = ignore_case + self.lookup = lookup def set_context(self, serializer_field): """ @@ -63,8 +63,7 @@ class UniqueValidator(object): """ Filter the queryset to all instances matching the given attribute. """ - field_lookup = 'iexact' if self.ignore_case else 'exact' - filter_kwargs = {'%s__%s' % (self.field_name, field_lookup): value} + filter_kwargs = {'%s__%s' % (self.field_name, self.lookup): value} return qs_filter(queryset, **filter_kwargs) def exclude_current_instance(self, queryset):