Ticket #13771: related_field_validation.patch

File related_field_validation.patch, 1.2 KB (added by jdetaeye, 14 years ago)

partial patch

  • django/db/models/fields/related.py

     
    828828        if value is None:
    829829            return
    830830
    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})
    832835        qs = qs.complex_filter(self.rel.limit_choices_to)
    833836        if not qs.exists():
    834837            raise exceptions.ValidationError(self.error_messages['invalid'] % {
     
    10541057        except ValueError:
    10551058            # the CommaSeparatedIntegerField validator will catch this error
    10561059            return
     1060        # TODO: this validation is not aware of the database to use in a multi-db configuration
    10571061        objects = mod._default_manager.in_bulk(pks)
    10581062        if len(objects) != len(pks):
    10591063            badkeys = [k for k in pks if k not in objects]
Back to Top