Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
 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