Ticket #17875: foreignkey-db-using.patch

File foreignkey-db-using.patch, 933 bytes (added by vital.fadeev@…, 7 years ago)
  • related.py

    old new class ForeignKey(RelatedField, Field): 
    836836    def validate(self, value, model_instance):
    837837        if self.rel.parent_link:
    838838            return
    839839        super(ForeignKey, self).validate(value, model_instance)
    840840        if value is None:
    841841            return
    842842
    843         using = router.db_for_read(model_instance.__class__, instance=model_instance)
     843        using = router.db_for_read(self.rel.to, instance=model_instance)
    844844        qs = self.rel.to._default_manager.using(using).filter(
    845845                **{self.rel.field_name: value}
    846846             )
    847847        qs = qs.complex_filter(self.rel.limit_choices_to)
    848848        if not qs.exists():
    849849            raise exceptions.ValidationError(self.error_messages['invalid'] % {
    850850                'model': self.rel.to._meta.verbose_name, 'pk': value})
Back to Top