def clean(self, value): Field.clean(self, value) if value in EMPTY_VALUES: return None try: value = self.queryset.get(pk=value) except self.queryset.model.DoesNotExist: raise ValidationError(self.error_messages['invalid_choice']) return value
def clean(self, value): Field.clean(self, value) if value in ('', None): return None try: value = self.queryset.model._default_manager.get(pk=value) except self.queryset.model.DoesNotExist: raise ValidationError(gettext(u'Select a valid choice. That choice is not one of the available choices.')) return value
def clean(self, value): Field.clean(self, value) if value in EMPTY_VALUES: return None if self.to_field_name: value = deepcopy(self.queryset).filter(self.to_field_name + ' =', value).get() else: value = self.queryset.model.get(value) if not value: raise ValidationError(self.error_messages['invalid_choice']) return value
def clean(self, value): Field.clean(self, value) if value in ('', None): return None try: value = self.queryset.model._default_manager.get(pk=value) except self.queryset.model.DoesNotExist: raise ValidationError( gettext( u'Select a valid choice. That choice is not one of the available choices.' )) return value