diff options
| author | Anubhav Joshi <anubhav9042@gmail.com> | 2014-06-30 18:36:28 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-07-03 07:42:52 -0400 |
| commit | 9bc2d766a0c31701a4c0e20a8b04164bb22cf6d5 (patch) | |
| tree | 478a6119acaed199052bbf37ec6ab7ce01d26080 /django/db/utils.py | |
| parent | 23d68c0f0d705fede71e1a99625d9988a63cdad3 (diff) | |
Fixed #21755 -- Added ForeignKey support to REQUIRED_FIELDS.
This allows specifying ForeignKeys in REQUIRED_FIELDS when using a
custom User model.
Thanks cjerdonek and bmispelon for suggestion and timgraham for review.
Diffstat (limited to 'django/db/utils.py')
| -rw-r--r-- | django/db/utils.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/django/db/utils.py b/django/db/utils.py index 4fb75e3150..f1f43ee5ed 100644 --- a/django/db/utils.py +++ b/django/db/utils.py @@ -286,10 +286,10 @@ class ConnectionRouter(object): chosen_db = method(model, **hints) if chosen_db: return chosen_db - try: - return hints['instance']._state.db or DEFAULT_DB_ALIAS - except KeyError: - return DEFAULT_DB_ALIAS + instance = hints.get('instance') + if instance is not None and instance._state.db: + return instance._state.db + return DEFAULT_DB_ALIAS return _route_db db_for_read = _router_func('db_for_read') |
