--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
You can't do this with a router; as you've noted, the router doesn't
have any information about the request in which it is being used.
However, you could do it by manually requesting your database
connection whenever you use the database. For example:
Author.objects.using('otherdb').filter(...)
will perform a query that is guaranteed to operate on the 'otherdb',
regardless of what the router says.
The parameter 'otherdb' is just a string, so it could be determined
using some logic based on the request. This will require that you pass
the database assignment information around your project -- but you
would have needed to do this anyway if you wanted to pass hints to the
router.
Yours,
Russ Magee %-)
You're in somewhat uncharted territory here, so I can't give you a
simple prepared answer. However, you certainly appear to be on the
right track.
It's also possible that you've discovered an edge case bug -- looking
at the code, my gut tells me that the _default_manager call should be
forced onto the same database as model_instance - i.e., the query
should be:
db = router.db_for_read(self.rel.to, instance=model_instance)
qs = self.re.to._default_manager.using(db).filter(**self.rel.field_name:value})
or similar. I'd need to do more tests to confirm this, though. Feel
free to log a bug if you can reduce this to a test case that
demonstrates that this is indeed a bug.
Yours,
Russ Magee %-)