Ticket #14257: rm_isValidIDList.diff

File rm_isValidIDList.diff, 1.3 KB (added by andrewsk, 4 years ago)
  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    index 1634d7d..ade5ddb 100644
    a b class ManyToManyField(RelatedField, Field): 
    10491049                    break
    10501050        return getattr(self, cache_attr)
    10511051
    1052     def isValidIDList(self, field_data, all_data):
    1053         "Validates that the value is a valid list of foreign keys"
    1054         mod = self.rel.to
    1055         try:
    1056             pks = map(int, field_data.split(','))
    1057         except ValueError:
    1058             # the CommaSeparatedIntegerField validator will catch this error
    1059             return
    1060         objects = mod._default_manager.in_bulk(pks)
    1061         if len(objects) != len(pks):
    1062             badkeys = [k for k in pks if k not in objects]
    1063             raise exceptions.ValidationError(
    1064                 ungettext("Please enter valid %(self)s IDs. The value %(value)r is invalid.",
    1065                           "Please enter valid %(self)s IDs. The values %(value)r are invalid.",
    1066                           len(badkeys)) % {
    1067                 'self': self.verbose_name,
    1068                 'value': len(badkeys) == 1 and badkeys[0] or tuple(badkeys),
    1069             })
    1070 
    10711052    def value_to_string(self, obj):
    10721053        data = ''
    10731054        if obj:
Back to Top