Ticket #13771: related_field_validation.patch
File related_field_validation.patch, 1.2 KB (added by , 14 years ago) |
---|
-
django/db/models/fields/related.py
828 828 if value is None: 829 829 return 830 830 831 qs = self.rel.to._default_manager.filter(**{self.rel.field_name:value}) 831 db = model_instance._state.db 832 if db is None: 833 db = router.db_for_write(model_instance.__class__, instance=model_instance) 834 qs = self.rel.to._default_manager.using(db).filter(**{self.rel.field_name:value}) 832 835 qs = qs.complex_filter(self.rel.limit_choices_to) 833 836 if not qs.exists(): 834 837 raise exceptions.ValidationError(self.error_messages['invalid'] % { … … 1054 1057 except ValueError: 1055 1058 # the CommaSeparatedIntegerField validator will catch this error 1056 1059 return 1060 # TODO: this validation is not aware of the database to use in a multi-db configuration 1057 1061 objects = mod._default_manager.in_bulk(pks) 1058 1062 if len(objects) != len(pks): 1059 1063 badkeys = [k for k in pks if k not in objects]