Ticket #8746: 8746.diff

File 8746.diff, 1.6 KB (added by David Gouldin, 16 years ago)
  • django/forms/models.py

     
    729729        'list': _(u'Enter a list of values.'),
    730730        'invalid_choice': _(u'Select a valid choice. %s is not one of the'
    731731                            u' available choices.'),
     732        'invalid_pk_value': _(u'"%s" is not a valid value for a primary key.')
    732733    }
    733734
    734735    def __init__(self, queryset, cache_choices=False, required=True,
     
    751752                obj = self.queryset.get(pk=val)
    752753            except self.queryset.model.DoesNotExist:
    753754                raise ValidationError(self.error_messages['invalid_choice'] % val)
     755            except ValueError:
     756                raise ValidationError(self.error_messages['invalid_pk_value'] % val)
    754757            else:
    755758                final_values.append(obj)
    756759        return final_values
  • tests/modeltests/model_forms/models.py

     
    857857Traceback (most recent call last):
    858858...
    859859ValidationError: [u'Enter a list of values.']
     860>>> f.clean(['fail'])
     861Traceback (most recent call last):
     862...
     863ValidationError: [u'"fail" is not a valid value for a primary key.']
    860864
    861865# Add a Category object *after* the ModelMultipleChoiceField has already been
    862866# instantiated. This proves clean() checks the database during clean() rather
Back to Top