Ticket #14691: multidb_foreignkey_validation_patch.diff

File multidb_foreignkey_validation_patch.diff, 796 bytes (added by marcop, 9 years ago)
  • django/db/models/fields/related.py

     
    834834        super(ForeignKey, self).validate(value, model_instance)
    835835        if value is None:
    836836            return
    837 
    838         qs = self.rel.to._default_manager.filter(**{self.rel.field_name:value})
     837       
     838        using = router.db_for_read(model_instance.__class__, instance=model_instance)
     839        qs = self.rel.to._default_manager.using(using).filter(**{self.rel.field_name:value})
    839840        qs = qs.complex_filter(self.rel.limit_choices_to)
    840841        if not qs.exists():
    841842            raise exceptions.ValidationError(self.error_messages['invalid'] % {
Back to Top