2012-08-12 04:20:59 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2015-01-28 20:35:27 +08:00
|
|
|
import warnings
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
from bisect import bisect
|
2015-01-07 08:16:35 +08:00
|
|
|
from collections import OrderedDict, defaultdict
|
|
|
|
from itertools import chain
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2013-12-24 19:25:17 +08:00
|
|
|
from django.apps import apps
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.conf import settings
|
2015-01-02 23:14:23 +08:00
|
|
|
from django.core.exceptions import FieldDoesNotExist
|
2015-04-05 00:07:46 +08:00
|
|
|
from django.db import connections
|
2015-01-02 23:14:23 +08:00
|
|
|
from django.db.models.fields import AutoField
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
from django.db.models.fields.proxy import OrderWrt
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db.models.fields.related import ManyToManyField
|
2012-07-20 20:22:00 +08:00
|
|
|
from django.utils import six
|
2015-02-04 04:13:43 +08:00
|
|
|
from django.utils.datastructures import ImmutableList, OrderedSet
|
2015-06-23 01:54:35 +08:00
|
|
|
from django.utils.deprecation import RemovedInDjango110Warning
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.utils.encoding import (
|
|
|
|
force_text, python_2_unicode_compatible, smart_text,
|
|
|
|
)
|
2014-02-27 05:48:20 +08:00
|
|
|
from django.utils.functional import cached_property
|
2015-01-07 08:16:35 +08:00
|
|
|
from django.utils.lru_cache import lru_cache
|
2013-12-26 20:46:15 +08:00
|
|
|
from django.utils.text import camel_case_to_spaces
|
2015-01-08 22:04:16 +08:00
|
|
|
from django.utils.translation import override, string_concat
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2015-02-16 15:49:19 +08:00
|
|
|
PROXY_PARENTS = object()
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
EMPTY_RELATION_TREE = tuple()
|
|
|
|
|
|
|
|
IMMUTABLE_WARNING = (
|
|
|
|
"The return type of '%s' should never be mutated. If you want to manipulate this list "
|
|
|
|
"for your own use, make a copy first."
|
|
|
|
)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2010-11-17 20:09:21 +08:00
|
|
|
DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
|
2006-05-02 09:31:56 +08:00
|
|
|
'unique_together', 'permissions', 'get_latest_by',
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
'order_with_respect_to', 'app_label', 'db_tablespace',
|
2012-11-05 02:16:06 +08:00
|
|
|
'abstract', 'managed', 'proxy', 'swappable', 'auto_created',
|
2013-12-24 19:25:17 +08:00
|
|
|
'index_together', 'apps', 'default_permissions',
|
2015-04-05 00:07:46 +08:00
|
|
|
'select_on_save', 'default_related_name',
|
|
|
|
'required_db_features', 'required_db_vendor')
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
class raise_deprecation(object):
|
|
|
|
def __init__(self, suggested_alternative):
|
|
|
|
self.suggested_alternative = suggested_alternative
|
|
|
|
|
|
|
|
def __call__(self, fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
warnings.warn(
|
|
|
|
"'%s is an unofficial API that has been deprecated. "
|
|
|
|
"You may be able to replace it with '%s'" % (
|
|
|
|
fn.__name__,
|
|
|
|
self.suggested_alternative,
|
|
|
|
),
|
2015-06-23 01:54:35 +08:00
|
|
|
RemovedInDjango110Warning, stacklevel=2
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
|
|
|
return fn(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
2014-03-02 03:06:15 +08:00
|
|
|
def normalize_together(option_together):
|
2013-10-07 15:37:35 +08:00
|
|
|
"""
|
2014-03-02 03:06:15 +08:00
|
|
|
option_together can be either a tuple of tuples, or a single
|
2013-10-07 15:37:35 +08:00
|
|
|
tuple of two strings. Normalize it to a tuple of tuples, so that
|
|
|
|
calling code can uniformly expect that.
|
|
|
|
"""
|
2014-01-20 10:45:21 +08:00
|
|
|
try:
|
2014-03-02 03:06:15 +08:00
|
|
|
if not option_together:
|
2014-01-20 10:45:21 +08:00
|
|
|
return ()
|
2014-03-02 03:06:15 +08:00
|
|
|
if not isinstance(option_together, (tuple, list)):
|
|
|
|
raise TypeError
|
|
|
|
first_element = next(iter(option_together))
|
2014-01-20 10:45:21 +08:00
|
|
|
if not isinstance(first_element, (tuple, list)):
|
2014-03-02 03:06:15 +08:00
|
|
|
option_together = (option_together,)
|
2014-01-20 10:45:21 +08:00
|
|
|
# Normalize everything to tuples
|
2014-03-02 03:06:15 +08:00
|
|
|
return tuple(tuple(ot) for ot in option_together)
|
2014-01-20 10:45:21 +08:00
|
|
|
except TypeError:
|
2014-03-02 03:06:15 +08:00
|
|
|
# If the value of option_together isn't valid, return it
|
2014-01-20 10:45:21 +08:00
|
|
|
# verbatim; this will be picked up by the check framework later.
|
2014-03-02 03:06:15 +08:00
|
|
|
return option_together
|
2013-10-07 15:37:35 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
def make_immutable_fields_list(name, data):
|
|
|
|
return ImmutableList(data, warning=IMMUTABLE_WARNING % name)
|
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2006-06-08 13:00:13 +08:00
|
|
|
class Options(object):
|
2015-01-07 08:16:35 +08:00
|
|
|
FORWARD_PROPERTIES = ('fields', 'many_to_many', 'concrete_fields',
|
|
|
|
'local_concrete_fields', '_forward_fields_map')
|
|
|
|
REVERSE_PROPERTIES = ('related_objects', 'fields_map', '_relation_tree')
|
|
|
|
|
2008-06-29 10:35:08 +08:00
|
|
|
def __init__(self, meta, app_label=None):
|
2015-01-07 08:16:35 +08:00
|
|
|
self._get_fields_cache = {}
|
|
|
|
self.proxied_children = []
|
2013-12-31 23:13:40 +08:00
|
|
|
self.local_fields = []
|
|
|
|
self.local_many_to_many = []
|
2008-09-02 23:26:00 +08:00
|
|
|
self.virtual_fields = []
|
2013-12-31 23:13:40 +08:00
|
|
|
self.model_name = None
|
|
|
|
self.verbose_name = None
|
2006-05-02 09:31:56 +08:00
|
|
|
self.verbose_name_plural = None
|
|
|
|
self.db_table = ''
|
|
|
|
self.ordering = []
|
2015-03-17 22:42:53 +08:00
|
|
|
self._ordering_clash = False
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
self.unique_together = []
|
2012-11-05 02:16:06 +08:00
|
|
|
self.index_together = []
|
2013-08-30 14:41:07 +08:00
|
|
|
self.select_on_save = False
|
2013-08-01 23:31:34 +08:00
|
|
|
self.default_permissions = ('add', 'change', 'delete')
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
self.permissions = []
|
2013-12-31 23:13:40 +08:00
|
|
|
self.object_name = None
|
|
|
|
self.app_label = app_label
|
2006-05-02 09:31:56 +08:00
|
|
|
self.get_latest_by = None
|
|
|
|
self.order_with_respect_to = None
|
2007-12-02 03:23:49 +08:00
|
|
|
self.db_tablespace = settings.DEFAULT_TABLESPACE
|
2015-04-05 00:07:46 +08:00
|
|
|
self.required_db_features = []
|
|
|
|
self.required_db_vendor = None
|
2006-05-02 09:31:56 +08:00
|
|
|
self.meta = meta
|
|
|
|
self.pk = None
|
2013-12-31 23:13:40 +08:00
|
|
|
self.has_auto_field = False
|
|
|
|
self.auto_field = None
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
self.abstract = False
|
2009-03-09 11:35:02 +08:00
|
|
|
self.managed = True
|
2009-03-18 17:47:08 +08:00
|
|
|
self.proxy = False
|
2012-03-03 01:16:52 +08:00
|
|
|
# For any class that is a proxy (including automatically created
|
|
|
|
# classes for deferred object loading), proxy_for_model tells us
|
2012-02-22 13:26:50 +08:00
|
|
|
# which class this model is proxying. Note that proxy_for_model
|
2012-03-03 01:16:52 +08:00
|
|
|
# can create a chain of proxy models. For non-proxy models, the
|
2012-02-22 13:26:50 +08:00
|
|
|
# variable is always None.
|
2009-03-18 17:47:08 +08:00
|
|
|
self.proxy_for_model = None
|
2012-03-03 01:16:52 +08:00
|
|
|
# For any non-abstract class, the concrete class is the model
|
2012-02-22 13:26:50 +08:00
|
|
|
# in the end of the proxy_for_model chain. In particular, for
|
2012-03-03 01:16:52 +08:00
|
|
|
# concrete models, the concrete_model is always the class itself.
|
2012-02-22 13:26:50 +08:00
|
|
|
self.concrete_model = None
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
self.swappable = None
|
2013-08-03 13:41:15 +08:00
|
|
|
self.parents = OrderedDict()
|
2009-11-03 22:02:49 +08:00
|
|
|
self.auto_created = False
|
2009-03-18 17:47:08 +08:00
|
|
|
|
|
|
|
# To handle various inheritance situations, we need to track where
|
2014-11-06 02:53:16 +08:00
|
|
|
# managers came from (concrete or abstract base classes). `managers`
|
|
|
|
# keeps a list of 3-tuples of the form:
|
|
|
|
# (creation_counter, instance, abstract(=True))
|
|
|
|
self.managers = []
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2011-01-28 22:08:25 +08:00
|
|
|
# List of all lookups defined in ForeignKey 'limit_choices_to' options
|
|
|
|
# from *other* models. Needed for some admin checks. Internal use only.
|
|
|
|
self.related_fkey_lookups = []
|
|
|
|
|
2013-12-24 19:25:17 +08:00
|
|
|
# A custom app registry to use, if you're making a separate model set.
|
|
|
|
self.apps = apps
|
2012-09-22 07:47:04 +08:00
|
|
|
|
2014-06-07 00:16:17 +08:00
|
|
|
self.default_related_name = None
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@lru_cache(maxsize=None)
|
|
|
|
def _map_model(self, link):
|
|
|
|
# This helper function is used to allow backwards compatibility with
|
|
|
|
# the previous API. No future methods should use this function.
|
|
|
|
# It maps a field to (field, model or related_model,) depending on the
|
|
|
|
# field type.
|
|
|
|
model = link.model._meta.concrete_model
|
|
|
|
if model is self.model:
|
|
|
|
model = None
|
|
|
|
return link, model
|
|
|
|
|
|
|
|
@lru_cache(maxsize=None)
|
|
|
|
def _map_model_details(self, link):
|
|
|
|
# This helper function is used to allow backwards compatibility with
|
|
|
|
# the previous API. No future methods should use this function.
|
|
|
|
# This function maps a field to a tuple of:
|
|
|
|
# (field, model or related_model, direct, is_m2m) depending on the
|
|
|
|
# field type.
|
|
|
|
direct = not link.auto_created or link.concrete
|
|
|
|
model = link.model._meta.concrete_model
|
|
|
|
if model is self.model:
|
|
|
|
model = None
|
|
|
|
m2m = link.is_relation and link.many_to_many
|
|
|
|
return link, model, direct, m2m
|
|
|
|
|
2015-04-27 05:05:50 +08:00
|
|
|
@property
|
|
|
|
def label(self):
|
|
|
|
return '%s.%s' % (self.app_label, self.object_name)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def label_lower(self):
|
|
|
|
return '%s.%s' % (self.app_label, self.model_name)
|
|
|
|
|
2013-12-17 02:30:33 +08:00
|
|
|
@property
|
|
|
|
def app_config(self):
|
2013-12-18 21:49:29 +08:00
|
|
|
# Don't go through get_app_config to avoid triggering imports.
|
2013-12-24 19:25:17 +08:00
|
|
|
return self.apps.app_configs.get(self.app_label)
|
2013-12-17 02:30:33 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def installed(self):
|
2013-12-18 20:16:33 +08:00
|
|
|
return self.app_config is not None
|
2013-12-17 02:30:33 +08:00
|
|
|
|
2014-11-06 02:53:16 +08:00
|
|
|
@property
|
|
|
|
def abstract_managers(self):
|
|
|
|
return [
|
|
|
|
(counter, instance.name, instance) for counter, instance, abstract
|
|
|
|
in self.managers if abstract
|
|
|
|
]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def concrete_managers(self):
|
|
|
|
return [
|
|
|
|
(counter, instance.name, instance) for counter, instance, abstract
|
|
|
|
in self.managers if not abstract
|
|
|
|
]
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
def contribute_to_class(self, cls, name):
|
2008-06-29 10:35:08 +08:00
|
|
|
from django.db import connection
|
2013-09-17 00:52:05 +08:00
|
|
|
from django.db.backends.utils import truncate_name
|
2008-06-29 10:35:08 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
cls._meta = self
|
2012-11-10 02:21:46 +08:00
|
|
|
self.model = cls
|
2006-05-02 09:31:56 +08:00
|
|
|
# First, construct the default values for these options.
|
|
|
|
self.object_name = cls.__name__
|
2013-02-05 17:16:07 +08:00
|
|
|
self.model_name = self.object_name.lower()
|
2013-12-26 20:46:15 +08:00
|
|
|
self.verbose_name = camel_case_to_spaces(self.object_name)
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
2013-05-19 18:35:17 +08:00
|
|
|
# Store the original user-defined values for each option,
|
|
|
|
# for use when serializing the model definition
|
|
|
|
self.original_attrs = {}
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
# Next, apply any overridden values from 'class Meta'.
|
|
|
|
if self.meta:
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
meta_attrs = self.meta.__dict__.copy()
|
2008-06-08 04:01:18 +08:00
|
|
|
for name in self.meta.__dict__:
|
|
|
|
# Ignore any private attributes that Django doesn't care about.
|
|
|
|
# NOTE: We can't modify a dictionary's contents while looping
|
|
|
|
# over it, so we loop over the *original* dictionary instead.
|
|
|
|
if name.startswith('_'):
|
|
|
|
del meta_attrs[name]
|
2006-05-02 09:31:56 +08:00
|
|
|
for attr_name in DEFAULT_NAMES:
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
if attr_name in meta_attrs:
|
|
|
|
setattr(self, attr_name, meta_attrs.pop(attr_name))
|
2013-05-19 18:35:17 +08:00
|
|
|
self.original_attrs[attr_name] = getattr(self, attr_name)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
elif hasattr(self.meta, attr_name):
|
|
|
|
setattr(self, attr_name, getattr(self.meta, attr_name))
|
2013-05-19 18:35:17 +08:00
|
|
|
self.original_attrs[attr_name] = getattr(self, attr_name)
|
2007-09-15 04:36:53 +08:00
|
|
|
|
2015-03-21 08:33:23 +08:00
|
|
|
self.unique_together = normalize_together(self.unique_together)
|
|
|
|
self.index_together = normalize_together(self.index_together)
|
2007-09-15 04:36:53 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
# verbose_name_plural is a special case because it uses a 's'
|
|
|
|
# by default.
|
2010-11-17 20:09:21 +08:00
|
|
|
if self.verbose_name_plural is None:
|
|
|
|
self.verbose_name_plural = string_concat(self.verbose_name, 's')
|
2007-09-15 04:36:53 +08:00
|
|
|
|
2015-03-17 22:42:53 +08:00
|
|
|
# order_with_respect_and ordering are mutually exclusive.
|
|
|
|
self._ordering_clash = bool(self.ordering and self.order_with_respect_to)
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
# Any leftover attributes must be invalid.
|
|
|
|
if meta_attrs != {}:
|
2010-01-11 02:36:20 +08:00
|
|
|
raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys()))
|
2006-05-02 09:31:56 +08:00
|
|
|
else:
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
self.verbose_name_plural = string_concat(self.verbose_name, 's')
|
2006-05-02 09:31:56 +08:00
|
|
|
del self.meta
|
|
|
|
|
2013-02-05 17:16:07 +08:00
|
|
|
# If the db_table wasn't provided, use the app_label + model_name.
|
2008-06-29 10:35:08 +08:00
|
|
|
if not self.db_table:
|
2013-02-05 17:16:07 +08:00
|
|
|
self.db_table = "%s_%s" % (self.app_label, self.model_name)
|
2008-06-29 10:35:08 +08:00
|
|
|
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
def _prepare(self, model):
|
|
|
|
if self.order_with_respect_to:
|
2015-01-07 08:16:35 +08:00
|
|
|
# The app registry will not be ready at this point, so we cannot
|
|
|
|
# use get_field().
|
|
|
|
query = self.order_with_respect_to
|
|
|
|
try:
|
|
|
|
self.order_with_respect_to = next(
|
|
|
|
f for f in self._get_fields(reverse=False)
|
|
|
|
if f.name == query or f.attname == query
|
|
|
|
)
|
|
|
|
except StopIteration:
|
|
|
|
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, query))
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
self.ordering = ('_order',)
|
2014-05-29 07:00:30 +08:00
|
|
|
if not any(isinstance(field, OrderWrt) for field in model._meta.local_fields):
|
|
|
|
model.add_to_class('_order', OrderWrt())
|
2006-05-02 09:31:56 +08:00
|
|
|
else:
|
|
|
|
self.order_with_respect_to = None
|
|
|
|
|
|
|
|
if self.pk is None:
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
if self.parents:
|
|
|
|
# Promote the first parent link in lieu of adding yet another
|
|
|
|
# field.
|
2012-07-21 03:14:27 +08:00
|
|
|
field = next(six.itervalues(self.parents))
|
2011-02-12 23:07:27 +08:00
|
|
|
# Look for a local field with the same name as the
|
|
|
|
# first parent link. If a local field has already been
|
|
|
|
# created, use it instead of promoting the parent
|
|
|
|
already_created = [fld for fld in self.local_fields if fld.name == field.name]
|
|
|
|
if already_created:
|
|
|
|
field = already_created[0]
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
field.primary_key = True
|
2008-06-09 22:03:35 +08:00
|
|
|
self.setup_pk(field)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
else:
|
|
|
|
auto = AutoField(verbose_name='ID', primary_key=True,
|
|
|
|
auto_created=True)
|
|
|
|
model.add_to_class('id', auto)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
def add_field(self, field, virtual=False):
|
2006-05-02 09:31:56 +08:00
|
|
|
# Insert the given field in the order in which it was created, using
|
|
|
|
# the "creation_counter" attribute of the field.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
# Move many-to-many related fields from self.fields into
|
|
|
|
# self.many_to_many.
|
2015-01-07 08:16:35 +08:00
|
|
|
if virtual:
|
|
|
|
self.virtual_fields.append(field)
|
|
|
|
elif field.is_relation and field.many_to_many:
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
self.local_many_to_many.insert(bisect(self.local_many_to_many, field), field)
|
2006-05-02 09:31:56 +08:00
|
|
|
else:
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
self.local_fields.insert(bisect(self.local_fields, field), field)
|
|
|
|
self.setup_pk(field)
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
# If the field being added is a relation to another known field,
|
|
|
|
# expire the cache on this field and the forward cache on the field
|
|
|
|
# being referenced, because there will be new relationships in the
|
|
|
|
# cache. Otherwise, expire the cache of references *to* this field.
|
|
|
|
# The mechanism for getting at the related model is slightly odd -
|
|
|
|
# ideally, we'd just ask for field.related_model. However, related_model
|
|
|
|
# is a cached property, and all the models haven't been loaded yet, so
|
|
|
|
# we need to make sure we don't cache a string reference.
|
2015-02-26 22:19:17 +08:00
|
|
|
if field.is_relation and hasattr(field.remote_field, 'model') and field.remote_field.model:
|
2015-01-07 08:16:35 +08:00
|
|
|
try:
|
2015-02-26 22:19:17 +08:00
|
|
|
field.remote_field.model._meta._expire_cache(forward=False)
|
2015-01-07 08:16:35 +08:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
self._expire_cache()
|
|
|
|
else:
|
|
|
|
self._expire_cache(reverse=False)
|
2008-09-02 23:26:00 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def setup_pk(self, field):
|
|
|
|
if not self.pk and field.primary_key:
|
|
|
|
self.pk = field
|
|
|
|
field.serialize = False
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2009-03-18 17:47:08 +08:00
|
|
|
def setup_proxy(self, target):
|
|
|
|
"""
|
|
|
|
Does the internal setup so that the current model is a proxy for
|
|
|
|
"target".
|
|
|
|
"""
|
|
|
|
self.pk = target._meta.pk
|
|
|
|
self.proxy_for_model = target
|
|
|
|
self.db_table = target._meta.db_table
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
def __repr__(self):
|
|
|
|
return '<Options for %s>' % self.object_name
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2013-02-05 17:16:07 +08:00
|
|
|
return "%s.%s" % (smart_text(self.app_label), smart_text(self.model_name))
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
|
2015-04-05 00:07:46 +08:00
|
|
|
def can_migrate(self, connection):
|
|
|
|
"""
|
|
|
|
Return True if the model can/should be migrated on the `connection`.
|
|
|
|
`connection` can be either a real connection or a connection alias.
|
|
|
|
"""
|
|
|
|
if self.proxy or self.swapped or not self.managed:
|
|
|
|
return False
|
|
|
|
if isinstance(connection, six.string_types):
|
|
|
|
connection = connections[connection]
|
|
|
|
if self.required_db_vendor:
|
|
|
|
return self.required_db_vendor == connection.vendor
|
|
|
|
if self.required_db_features:
|
|
|
|
return all(getattr(connection.features, feat, False)
|
|
|
|
for feat in self.required_db_features)
|
|
|
|
return True
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@property
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 20:11:04 +08:00
|
|
|
def verbose_name_raw(self):
|
|
|
|
"""
|
|
|
|
There are a few places where the untranslated verbose name is needed
|
|
|
|
(so that we get the same value regardless of currently active
|
|
|
|
locale).
|
|
|
|
"""
|
2015-01-08 22:04:16 +08:00
|
|
|
with override(None):
|
|
|
|
return force_text(self.verbose_name)
|
2007-06-23 22:16:00 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@property
|
|
|
|
def swapped(self):
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
"""
|
|
|
|
Has this model been swapped out for another? If so, return the model
|
|
|
|
name of the replacement; otherwise, return None.
|
2012-12-20 16:10:19 +08:00
|
|
|
|
|
|
|
For historical reasons, model name lookups using get_model() are
|
|
|
|
case insensitive, so we make sure we are case insensitive here.
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
"""
|
|
|
|
if self.swappable:
|
|
|
|
swapped_for = getattr(settings, self.swappable, None)
|
2012-12-20 16:10:19 +08:00
|
|
|
if swapped_for:
|
|
|
|
try:
|
|
|
|
swapped_label, swapped_object = swapped_for.split('.')
|
|
|
|
except ValueError:
|
|
|
|
# setting not in the format app_label.model_name
|
|
|
|
# raising ImproperlyConfigured here causes problems with
|
|
|
|
# test cleanup code - instead it is raised in get_user_model
|
|
|
|
# or as part of validation.
|
|
|
|
return swapped_for
|
|
|
|
|
2015-04-27 05:05:50 +08:00
|
|
|
if '%s.%s' % (swapped_label, swapped_object.lower()) not in (None, self.label_lower):
|
2012-12-20 16:10:19 +08:00
|
|
|
return swapped_for
|
Fixed #3011 -- Added swappable auth.User models.
Thanks to the many people that contributed to the development and review of
this patch, including (but not limited to) Jacob Kaplan-Moss, Anssi
Kääriäinen, Ramiro Morales, Preston Holmes, Josh Ourisman, Thomas Sutton,
and Roger Barnes, as well as the many, many people who have contributed to
the design discussion around this ticket over many years.
Squashed commit of the following:
commit d84749a0f034a0a6906d20df047086b1219040d0
Merge: 531e771 7c11b1a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 18:37:04 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 531e7715da545f930c49919a19e954d41c59b446
Merge: 29d1abb 1f84b04
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Wed Sep 26 07:09:23 2012 +0800
Merged recent trunk changes.
commit 29d1abbe351fd5da855fe5ce09e24227d90ddc91
Merge: 8a527dd 54c81a1
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:49:46 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8a527dda13c9bec955b1f7e8db5822d1d9b32a01
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 24 07:48:05 2012 +0800
Ensure sequences are reset correctly in the presence of swapped models.
commit e2b6e22f298eb986d74d28b8d9906f37f5ff8eb8
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 17:53:05 2012 +0800
Modifications to the handling and docs for auth forms.
commit 98aba856b534620aea9091f824b442b47d2fdb3c
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 15:28:57 2012 +0800
Improved error handling and docs for get_user_model()
commit 0229209c844f06dfeb33b0b8eeec000c127695b6
Merge: 6494bf9 8599f64
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 23 14:50:11 2012 +0800
Merged recent Django trunk changes.
commit 6494bf91f2ddaaabec3ec017f2e3131937c35517
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 21:38:44 2012 +0800
Improved validation of swappable model settings.
commit 5a04cde342cc860384eb844cfda5af55204564ad
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Sep 17 07:15:14 2012 +0800
Removed some unused imports.
commit ffd535e4136dc54f084b6ac467e81444696e1c8a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:31:28 2012 +0800
Corrected attribute access on for get_by_natural_key
commit 913e1ac84c3d9c7c58a9b3bdbbb15ebccd8a8c0a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 20:12:34 2012 +0800
Added test for proxy model safeguards on swappable models.
commit 280bf19e94d0d534d0e51bae485c1842558f4ff4
Merge: dbb3900 935a863
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:16:49 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit dbb3900775a99df8b6cb1d7063cf364eab55621a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 18:09:27 2012 +0800
Fixes for Python 3 compatibility.
commit dfd72131d8664615e245aa0f95b82604ba6b3821
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:54:30 2012 +0800
Added protection against proxying swapped models.
commit abcb027190e53613e7f1734e77ee185b2587de31
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 15:11:10 2012 +0800
Cleanup and documentation of AbstractUser base class.
commit a9491a87763e307f0eb0dc246f54ac865a6ffb34
Merge: fd8bb4e 08bcb4a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:46:49 2012 +0800
Merge commit '08bcb4aec1ed154cefc631b8510ee13e9af0c19d' into t3011
commit fd8bb4e3e498a92d7a8b340f0684d5f088aa4c92
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 14:20:14 2012 +0800
Documentation improvements coming from community review.
commit b550a6d06d016ab6a0198c4cb2dffe9cceabe8a5
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:52:47 2012 +0800
Refactored skipIfCustomUser into the contrib.auth tests.
commit 52a02f11107c3f0d711742b8ca65b75175b79d6a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:46:10 2012 +0800
Refactored common 'get' pattern into manager method.
commit b441a6bbc7d6065175715cb09316b9f13268171b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 16 13:41:33 2012 +0800
Added note about backwards incompatible change to admin login messages.
commit 08bcb4aec1ed154cefc631b8510ee13e9af0c19d
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:33 2012 +0300
Splitted User to AbstractUser and User
commit d9f5e5addbad5e1a01f67e7358e4f5091c3cad81
Author: Anssi Kääriäinen <akaariai@gmail.com>
Date: Sat Sep 15 18:30:02 2012 +0300
Reworked REQUIRED_FIELDS + create_user() interaction
commit 579f152e4a6e06671e1ac1e59e2b43cf4d764bf4
Merge: 9184972 93e6733
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:37 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 918497218c58227f5032873ff97261627b2ceab2
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:18:19 2012 +0800
Deprecate AUTH_PROFILE_MODULE and get_profile().
commit 334cdfc1bb6a6794791497cdefda843bca2ea57a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 20:00:12 2012 +0800
Added release notes for new swappable User feature.
commit 5d7bb22e8d913b51aba1c3360e7af8b01b6c0ab6
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 19:59:49 2012 +0800
Ensure swapped models can't be queried.
commit 57ac6e3d32605a67581e875b37ec5b2284711a32
Merge: f2ec915 abfba3b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 15 14:31:54 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit f2ec915b20f81c8afeaa3df25f80689712f720f8
Merge: 1952656 5e99a3d
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:29:51 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 19526563b54fa300785c49cfb625c0c6158ced67
Merge: 2c5e833 c4aa26a
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 08:22:26 2012 +0800
Merge recent changes from master.
commit 2c5e833a30bef4305d55eacc0703533152f5c427
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 07:53:46 2012 +0800
Corrected admin_views tests following removal of the email fallback on admin logins.
commit 20d1892491839d6ef21f37db4ca136935c2076bf
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sun Sep 9 01:00:37 2012 +0800
Added conditional skips for all tests dependent on the default User model
commit 40ea8b888284775481fc1eaadeff267dbd7e3dfa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:47:02 2012 +0800
Added documentation for REQUIRED_FIELDS in custom auth.
commit e6aaf659708cf6491f5485d3edfa616cb9214cc0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Sat Sep 8 23:20:02 2012 +0800
Added first draft of custom User docs.
Thanks to Greg Turner for the initial text.
commit 75118bd242eec87649da2859e8c50a199a8a1dca
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 11:17:26 2012 +0800
Admin app should not allow username discovery
The admin app login form should not allow users to discover the username
associated with an email address.
commit d088b3af58dad7449fc58493193a327725c57c22
Author: Thomas Sutton <me@thomas-sutton.id.au>
Date: Mon Aug 20 10:32:13 2012 +0800
Admin app login form should use swapped user model
commit 7e82e83d67ee0871a72e1a3a723afdd214fcefc3
Merge: e29c010 39aa890
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Fri Sep 7 23:45:03 2012 +0800
Merged master changes.
commit e29c010beb96ca07697c4e3e0c0d5d3ffdc4c0a3
Merge: 8e3fd70 30bdf22
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:12:57 2012 +0800
Merge remote-tracking branch 'django/master' into t3011
commit 8e3fd703d02c31a4c3ac9f51f5011d03c0bd47f6
Merge: 507bb50 26e0ba0
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Aug 20 13:09:09 2012 +0800
Merged recent changes from trunk.
commit 507bb50a9291bfcdcfa1198f9fea21d4e3b1e762
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:41:37 2012 +0800
Modified auth app so that login with alternate auth app is possible.
commit dabe3628362ab7a4a6c9686dd874803baa997eaa
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 20:10:51 2012 +0800
Modified auth management commands to handle custom user definitions.
commit 7cc0baf89d490c92ef3f1dc909b8090191a1294b
Author: Russell Keith-Magee <russell@keith-magee.com>
Date: Mon Jun 4 14:17:28 2012 +0800
Added model Meta option for swappable models, and made auth.User a swappable model
2012-09-26 18:48:09 +08:00
|
|
|
return None
|
|
|
|
|
2013-03-25 00:40:40 +08:00
|
|
|
@cached_property
|
|
|
|
def fields(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
Returns a list of all forward fields on the model and its parents,
|
|
|
|
excluding ManyToManyFields.
|
|
|
|
|
|
|
|
Private API intended only to be used by Django itself; get_fields()
|
|
|
|
combined with filtering of field properties is the public API for
|
|
|
|
obtaining this field list.
|
|
|
|
"""
|
|
|
|
# For legacy reasons, the fields property should only contain forward
|
|
|
|
# fields that are not virtual or with a m2m cardinality. Therefore we
|
|
|
|
# pass these three filters as filters to the generator.
|
|
|
|
# The third lambda is a longwinded way of checking f.related_model - we don't
|
|
|
|
# use that property directly because related_model is a cached property,
|
|
|
|
# and all the models may not have been loaded yet; we don't want to cache
|
|
|
|
# the string reference to the related_model.
|
|
|
|
is_not_an_m2m_field = lambda f: not (f.is_relation and f.many_to_many)
|
2015-02-14 02:55:36 +08:00
|
|
|
is_not_a_generic_relation = lambda f: not (f.is_relation and f.one_to_many)
|
2015-01-07 08:16:35 +08:00
|
|
|
is_not_a_generic_foreign_key = lambda f: not (
|
2015-02-26 22:19:17 +08:00
|
|
|
f.is_relation and f.many_to_one and not (hasattr(f.remote_field, 'model') and f.remote_field.model)
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
|
|
|
return make_immutable_fields_list(
|
|
|
|
"fields",
|
|
|
|
(f for f in self._get_fields(reverse=False) if
|
|
|
|
is_not_an_m2m_field(f) and is_not_a_generic_relation(f)
|
|
|
|
and is_not_a_generic_foreign_key(f))
|
|
|
|
)
|
2013-03-25 00:40:40 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def concrete_fields(self):
|
2015-01-07 08:16:35 +08:00
|
|
|
"""
|
|
|
|
Returns a list of all concrete fields on the model and its parents.
|
|
|
|
|
|
|
|
Private API intended only to be used by Django itself; get_fields()
|
|
|
|
combined with filtering of field properties is the public API for
|
|
|
|
obtaining this field list.
|
|
|
|
"""
|
|
|
|
return make_immutable_fields_list(
|
|
|
|
"concrete_fields", (f for f in self.fields if f.concrete)
|
|
|
|
)
|
2013-03-25 00:40:40 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def local_concrete_fields(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
Returns a list of all concrete fields on the model.
|
|
|
|
|
|
|
|
Private API intended only to be used by Django itself; get_fields()
|
|
|
|
combined with filtering of field properties is the public API for
|
|
|
|
obtaining this field list.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
return make_immutable_fields_list(
|
|
|
|
"local_concrete_fields", (f for f in self.local_fields if f.concrete)
|
|
|
|
)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
|
|
|
def get_fields_with_model(self):
|
|
|
|
return [self._map_model(f) for f in self.get_fields()]
|
2013-03-25 00:40:40 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
|
|
|
def get_concrete_fields_with_model(self):
|
|
|
|
return [self._map_model(f) for f in self.concrete_fields]
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@cached_property
|
|
|
|
def many_to_many(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
Returns a list of all many to many fields on the model and its parents.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
Private API intended only to be used by Django itself; get_fields()
|
|
|
|
combined with filtering of field properties is the public API for
|
|
|
|
obtaining this list.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
return make_immutable_fields_list(
|
|
|
|
"many_to_many",
|
|
|
|
(f for f in self._get_fields(reverse=False)
|
|
|
|
if f.is_relation and f.many_to_many)
|
|
|
|
)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@cached_property
|
|
|
|
def related_objects(self):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
Returns all related objects pointing to the current model. The related
|
|
|
|
objects can come from a one-to-one, one-to-many, or many-to-many field
|
|
|
|
relation type.
|
|
|
|
|
|
|
|
Private API intended only to be used by Django itself; get_fields()
|
|
|
|
combined with filtering of field properties is the public API for
|
|
|
|
obtaining this field list.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
all_related_fields = self._get_fields(forward=False, reverse=True, include_hidden=True)
|
|
|
|
return make_immutable_fields_list(
|
|
|
|
"related_objects",
|
|
|
|
(obj for obj in all_related_fields
|
|
|
|
if not obj.hidden or obj.field.many_to_many)
|
|
|
|
)
|
|
|
|
|
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
|
|
|
def get_m2m_with_model(self):
|
|
|
|
return [self._map_model(f) for f in self.many_to_many]
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def _forward_fields_map(self):
|
|
|
|
res = {}
|
|
|
|
fields = self._get_fields(reverse=False)
|
|
|
|
for field in fields:
|
|
|
|
res[field.name] = field
|
|
|
|
# Due to the way Django's internals work, get_field() should also
|
|
|
|
# be able to fetch a field by attname. In the case of a concrete
|
|
|
|
# field with relation, includes the *_id name too
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
try:
|
2015-01-07 08:16:35 +08:00
|
|
|
res[field.attname] = field
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
except AttributeError:
|
2015-01-07 08:16:35 +08:00
|
|
|
pass
|
|
|
|
return res
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@cached_property
|
|
|
|
def fields_map(self):
|
|
|
|
res = {}
|
|
|
|
fields = self._get_fields(forward=False, include_hidden=True)
|
|
|
|
for field in fields:
|
|
|
|
res[field.name] = field
|
|
|
|
# Due to the way Django's internals work, get_field() should also
|
|
|
|
# be able to fetch a field by attname. In the case of a concrete
|
|
|
|
# field with relation, includes the *_id name too
|
|
|
|
try:
|
|
|
|
res[field.attname] = field
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
return res
|
|
|
|
|
|
|
|
def get_field(self, field_name, many_to_many=None):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
Returns a field instance given a field name. The field can be either a
|
|
|
|
forward or reverse field, unless many_to_many is specified; if it is,
|
|
|
|
only forward fields will be returned.
|
|
|
|
|
|
|
|
The many_to_many argument exists for backwards compatibility reasons;
|
2015-06-23 01:54:35 +08:00
|
|
|
it has been deprecated and will be removed in Django 1.10.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-01-07 08:16:35 +08:00
|
|
|
m2m_in_kwargs = many_to_many is not None
|
|
|
|
if m2m_in_kwargs:
|
|
|
|
# Always throw a warning if many_to_many is used regardless of
|
|
|
|
# whether it alters the return type or not.
|
|
|
|
warnings.warn(
|
|
|
|
"The 'many_to_many' argument on get_field() is deprecated; "
|
|
|
|
"use a filter on field.many_to_many instead.",
|
2015-06-23 01:54:35 +08:00
|
|
|
RemovedInDjango110Warning
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
try:
|
2015-01-07 08:16:35 +08:00
|
|
|
# In order to avoid premature loading of the relation tree
|
|
|
|
# (expensive) we prefer checking if the field is a forward field.
|
|
|
|
field = self._forward_fields_map[field_name]
|
|
|
|
|
|
|
|
if many_to_many is False and field.many_to_many:
|
|
|
|
raise FieldDoesNotExist(
|
|
|
|
'%s has no field named %r' % (self.object_name, field_name)
|
|
|
|
)
|
|
|
|
|
|
|
|
return field
|
|
|
|
except KeyError:
|
2015-02-04 04:12:28 +08:00
|
|
|
# If the app registry is not ready, reverse fields are
|
|
|
|
# unavailable, therefore we throw a FieldDoesNotExist exception.
|
2015-02-11 01:15:54 +08:00
|
|
|
if not self.apps.models_ready:
|
2015-01-07 08:16:35 +08:00
|
|
|
raise FieldDoesNotExist(
|
2015-01-15 02:40:31 +08:00
|
|
|
"%s has no field named %r. The app cache isn't ready yet, "
|
2015-02-04 04:12:28 +08:00
|
|
|
"so if this is an auto-created related field, it won't "
|
2015-01-07 08:16:35 +08:00
|
|
|
"be available yet." % (self.object_name, field_name)
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
2015-02-04 04:12:28 +08:00
|
|
|
if m2m_in_kwargs:
|
|
|
|
# Previous API does not allow searching reverse fields.
|
|
|
|
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
# Retrieve field instance by name from cached or just-computed
|
|
|
|
# field map.
|
|
|
|
return self.fields_map[field_name]
|
|
|
|
except KeyError:
|
|
|
|
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
|
|
|
|
|
|
|
|
@raise_deprecation(suggested_alternative="get_field()")
|
|
|
|
def get_field_by_name(self, name):
|
|
|
|
return self._map_model_details(self.get_field(name))
|
|
|
|
|
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
|
|
|
def get_all_field_names(self):
|
|
|
|
names = set()
|
|
|
|
fields = self.get_fields()
|
|
|
|
for field in fields:
|
|
|
|
# For backwards compatibility GenericForeignKey should not be
|
|
|
|
# included in the results.
|
2015-02-14 02:55:36 +08:00
|
|
|
if field.is_relation and field.many_to_one and field.related_model is None:
|
2015-01-07 08:16:35 +08:00
|
|
|
continue
|
2015-02-16 15:49:19 +08:00
|
|
|
# Relations to child proxy models should not be included.
|
|
|
|
if (field.model != self.model and
|
|
|
|
field.model._meta.concrete_model == self.concrete_model):
|
|
|
|
continue
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
names.add(field.name)
|
|
|
|
if hasattr(field, 'attname'):
|
|
|
|
names.add(field.attname)
|
|
|
|
return list(names)
|
|
|
|
|
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
2012-03-05 11:41:01 +08:00
|
|
|
def get_all_related_objects(self, local_only=False, include_hidden=False,
|
|
|
|
include_proxy_eq=False):
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-02-16 15:49:19 +08:00
|
|
|
include_parents = True if local_only is False else PROXY_PARENTS
|
2015-01-07 08:16:35 +08:00
|
|
|
fields = self._get_fields(
|
|
|
|
forward=False, reverse=True,
|
|
|
|
include_parents=include_parents,
|
|
|
|
include_hidden=include_hidden,
|
|
|
|
)
|
|
|
|
fields = (obj for obj in fields if not isinstance(obj.field, ManyToManyField))
|
|
|
|
if include_proxy_eq:
|
|
|
|
children = chain.from_iterable(c._relation_tree
|
|
|
|
for c in self.concrete_model._meta.proxied_children
|
|
|
|
if c is not self)
|
2015-02-26 22:19:17 +08:00
|
|
|
relations = (f.remote_field for f in children
|
|
|
|
if include_hidden or not f.remote_field.field.remote_field.is_hidden())
|
2015-01-07 08:16:35 +08:00
|
|
|
fields = chain(fields, relations)
|
|
|
|
return list(fields)
|
|
|
|
|
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
|
|
|
def get_all_related_objects_with_model(self, local_only=False, include_hidden=False,
|
2012-03-05 11:41:01 +08:00
|
|
|
include_proxy_eq=False):
|
2015-01-07 08:16:35 +08:00
|
|
|
return [
|
|
|
|
self._map_model(f) for f in self.get_all_related_objects(
|
|
|
|
local_only=local_only,
|
|
|
|
include_hidden=include_hidden,
|
|
|
|
include_proxy_eq=include_proxy_eq,
|
|
|
|
)
|
|
|
|
]
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def get_all_related_many_to_many_objects(self, local_only=False):
|
2015-02-16 15:49:19 +08:00
|
|
|
include_parents = True if local_only is not True else PROXY_PARENTS
|
2015-01-07 08:16:35 +08:00
|
|
|
fields = self._get_fields(
|
|
|
|
forward=False, reverse=True,
|
2015-02-16 15:49:19 +08:00
|
|
|
include_parents=include_parents, include_hidden=True
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
|
|
|
return [obj for obj in fields if isinstance(obj.field, ManyToManyField)]
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
@raise_deprecation(suggested_alternative="get_fields()")
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def get_all_related_m2m_objects_with_model(self):
|
2015-01-07 08:16:35 +08:00
|
|
|
fields = self._get_fields(forward=False, reverse=True, include_hidden=True)
|
|
|
|
return [self._map_model(obj) for obj in fields if isinstance(obj.field, ManyToManyField)]
|
2006-05-02 09:31:56 +08:00
|
|
|
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
def get_base_chain(self, model):
|
|
|
|
"""
|
|
|
|
Returns a list of parent classes leading to 'model' (order from closet
|
|
|
|
to most distant ancestor). This has to handle the case were 'model' is
|
2014-05-29 08:39:14 +08:00
|
|
|
a grandparent or even more distant relation.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
|
|
|
if not self.parents:
|
2012-11-10 02:21:46 +08:00
|
|
|
return None
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
if model in self.parents:
|
|
|
|
return [model]
|
|
|
|
for parent in self.parents:
|
|
|
|
res = parent._meta.get_base_chain(model)
|
|
|
|
if res:
|
|
|
|
res.insert(0, parent)
|
|
|
|
return res
|
2012-11-10 02:21:46 +08:00
|
|
|
return None
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
|
|
|
|
def get_parent_list(self):
|
|
|
|
"""
|
2015-02-04 04:13:43 +08:00
|
|
|
Returns all the ancestors of this model as a list ordered by MRO.
|
|
|
|
Useful for determining if something is an ancestor, regardless of lineage.
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
"""
|
2015-02-04 04:13:43 +08:00
|
|
|
result = OrderedSet(self.parents)
|
Merged the queryset-refactor branch into trunk.
This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.
Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7477 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-04-27 10:50:16 +08:00
|
|
|
for parent in self.parents:
|
2015-02-04 04:13:43 +08:00
|
|
|
for ancestor in parent._meta.get_parent_list():
|
|
|
|
result.add(ancestor)
|
|
|
|
return list(result)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2009-03-04 15:20:08 +08:00
|
|
|
def get_ancestor_link(self, ancestor):
|
|
|
|
"""
|
|
|
|
Returns the field on the current model which points to the given
|
|
|
|
"ancestor". This is possible an indirect link (a pointer to a parent
|
|
|
|
model, which points, eventually, to the ancestor). Used when
|
|
|
|
constructing table joins for model inheritance.
|
|
|
|
|
|
|
|
Returns None if the model isn't an ancestor of this one.
|
|
|
|
"""
|
|
|
|
if ancestor in self.parents:
|
|
|
|
return self.parents[ancestor]
|
|
|
|
for parent in self.parents:
|
2009-05-11 18:10:03 +08:00
|
|
|
# Tries to get a link field from the immediate parent
|
|
|
|
parent_link = parent._meta.get_ancestor_link(ancestor)
|
|
|
|
if parent_link:
|
|
|
|
# In case of a proxied model, the first link
|
|
|
|
# of the chain to the ancestor is that parent
|
|
|
|
# links
|
|
|
|
return self.parents[parent] or parent_link
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
def _populate_directed_relation_graph(self):
|
|
|
|
"""
|
|
|
|
This method is used by each model to find its reverse objects. As this
|
|
|
|
method is very expensive and is accessed frequently (it looks up every
|
|
|
|
field in a model, in every app), it is computed on first access and then
|
|
|
|
is set as a property on every model.
|
|
|
|
"""
|
|
|
|
related_objects_graph = defaultdict(list)
|
|
|
|
|
|
|
|
all_models = self.apps.get_models(include_auto_created=True)
|
|
|
|
for model in all_models:
|
2015-02-16 15:49:19 +08:00
|
|
|
# Abstract model's fields are copied to child models, hence we will
|
|
|
|
# see the fields from the child models.
|
|
|
|
if model._meta.abstract:
|
|
|
|
continue
|
2015-01-07 08:16:35 +08:00
|
|
|
fields_with_relations = (
|
2015-02-16 15:49:19 +08:00
|
|
|
f for f in model._meta._get_fields(reverse=False, include_parents=False)
|
2015-01-07 08:16:35 +08:00
|
|
|
if f.is_relation and f.related_model is not None
|
|
|
|
)
|
|
|
|
for f in fields_with_relations:
|
2015-02-26 22:19:17 +08:00
|
|
|
if not isinstance(f.remote_field.model, six.string_types):
|
|
|
|
related_objects_graph[f.remote_field.model._meta].append(f)
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
for model in all_models:
|
|
|
|
# Set the relation_tree using the internal __dict__. In this way
|
|
|
|
# we avoid calling the cached property. In attribute lookup,
|
|
|
|
# __dict__ takes precedence over a data descriptor (such as
|
|
|
|
# @cached_property). This means that the _meta._relation_tree is
|
|
|
|
# only called if related_objects is not in __dict__.
|
|
|
|
related_objects = related_objects_graph[model._meta]
|
2015-02-16 15:49:19 +08:00
|
|
|
model._meta.__dict__['_relation_tree'] = related_objects
|
|
|
|
# It seems it is possible that self is not in all_models, so guard
|
|
|
|
# against that with default for get().
|
|
|
|
return self.__dict__.get('_relation_tree', EMPTY_RELATION_TREE)
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def _relation_tree(self):
|
2015-02-16 15:49:19 +08:00
|
|
|
return self._populate_directed_relation_graph()
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
def _expire_cache(self, forward=True, reverse=True):
|
|
|
|
# This method is usually called by apps.cache_clear(), when the
|
|
|
|
# registry is finalized, or when a new field is added.
|
|
|
|
properties_to_expire = []
|
|
|
|
if forward:
|
|
|
|
properties_to_expire.extend(self.FORWARD_PROPERTIES)
|
|
|
|
if reverse and not self.abstract:
|
|
|
|
properties_to_expire.extend(self.REVERSE_PROPERTIES)
|
|
|
|
|
|
|
|
for cache_key in properties_to_expire:
|
|
|
|
try:
|
|
|
|
delattr(self, cache_key)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self._get_fields_cache = {}
|
|
|
|
|
|
|
|
def get_fields(self, include_parents=True, include_hidden=False):
|
|
|
|
"""
|
2015-05-09 01:18:48 +08:00
|
|
|
Returns a list of fields associated to the model. By default, includes
|
|
|
|
forward and reverse fields, fields derived from inheritance, but not
|
|
|
|
hidden fields. The returned fields can be changed using the parameters:
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
- include_parents: include fields derived from inheritance
|
|
|
|
- include_hidden: include fields that have a related_name that
|
|
|
|
starts with a "+"
|
|
|
|
"""
|
2015-02-16 15:49:19 +08:00
|
|
|
if include_parents is False:
|
|
|
|
include_parents = PROXY_PARENTS
|
2015-01-07 08:16:35 +08:00
|
|
|
return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
|
|
|
|
|
|
|
|
def _get_fields(self, forward=True, reverse=True, include_parents=True, include_hidden=False,
|
2015-02-16 15:49:19 +08:00
|
|
|
seen_models=None):
|
|
|
|
"""
|
|
|
|
Internal helper function to return fields of the model.
|
|
|
|
* If forward=True, then fields defined on this model are returned.
|
|
|
|
* If reverse=True, then relations pointing to this model are returned.
|
|
|
|
* If include_hidden=True, then fields with is_hidden=True are returned.
|
|
|
|
* The include_parents argument toggles if fields from parent models
|
|
|
|
should be included. It has three values: True, False, and
|
|
|
|
PROXY_PARENTS. When set to PROXY_PARENTS, the call will return all
|
|
|
|
fields defined for the current model or any of its parents in the
|
|
|
|
parent chain to the model's concrete model.
|
|
|
|
"""
|
|
|
|
if include_parents not in (True, False, PROXY_PARENTS):
|
|
|
|
raise TypeError("Invalid argument for include_parents: %s" % (include_parents,))
|
2015-01-07 08:16:35 +08:00
|
|
|
# This helper function is used to allow recursion in ``get_fields()``
|
|
|
|
# implementation and to provide a fast way for Django's internals to
|
|
|
|
# access specific subsets of fields.
|
|
|
|
|
2015-02-16 15:49:19 +08:00
|
|
|
# We must keep track of which models we have already seen. Otherwise we
|
|
|
|
# could include the same field multiple times from different models.
|
|
|
|
topmost_call = False
|
|
|
|
if seen_models is None:
|
|
|
|
seen_models = set()
|
|
|
|
topmost_call = True
|
|
|
|
seen_models.add(self.model)
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
# Creates a cache key composed of all arguments
|
2015-02-16 15:49:19 +08:00
|
|
|
cache_key = (forward, reverse, include_parents, include_hidden, topmost_call)
|
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
try:
|
|
|
|
# In order to avoid list manipulation. Always return a shallow copy
|
|
|
|
# of the results.
|
|
|
|
return self._get_fields_cache[cache_key]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
2015-02-16 15:49:19 +08:00
|
|
|
fields = []
|
|
|
|
# Recursively call _get_fields() on each parent, with the same
|
|
|
|
# options provided in this call.
|
|
|
|
if include_parents is not False:
|
|
|
|
for parent in self.parents:
|
|
|
|
# In diamond inheritance it is possible that we see the same
|
|
|
|
# model from two different routes. In that case, avoid adding
|
|
|
|
# fields from the same parent again.
|
|
|
|
if parent in seen_models:
|
|
|
|
continue
|
|
|
|
if (parent._meta.concrete_model != self.concrete_model and
|
|
|
|
include_parents == PROXY_PARENTS):
|
|
|
|
continue
|
|
|
|
for obj in parent._meta._get_fields(
|
|
|
|
forward=forward, reverse=reverse, include_parents=include_parents,
|
|
|
|
include_hidden=include_hidden, seen_models=seen_models):
|
|
|
|
if hasattr(obj, 'parent_link') and obj.parent_link:
|
|
|
|
continue
|
|
|
|
fields.append(obj)
|
|
|
|
if reverse:
|
2015-01-07 08:16:35 +08:00
|
|
|
# Tree is computed once and cached until the app cache is expired.
|
|
|
|
# It is composed of a list of fields pointing to the current model
|
2015-02-16 15:49:19 +08:00
|
|
|
# from other models.
|
|
|
|
all_fields = self._relation_tree
|
|
|
|
for field in all_fields:
|
2015-01-07 08:16:35 +08:00
|
|
|
# If hidden fields should be included or the relation is not
|
|
|
|
# intentionally hidden, add to the fields dict.
|
2015-02-26 22:19:17 +08:00
|
|
|
if include_hidden or not field.remote_field.hidden:
|
|
|
|
fields.append(field.remote_field)
|
2015-02-16 15:49:19 +08:00
|
|
|
|
2015-01-07 08:16:35 +08:00
|
|
|
if forward:
|
2015-02-16 15:49:19 +08:00
|
|
|
fields.extend(
|
|
|
|
field for field in chain(self.local_fields, self.local_many_to_many)
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
2015-02-16 15:49:19 +08:00
|
|
|
# Virtual fields are recopied to each child model, and they get a
|
|
|
|
# different model as field.model in each child. Hence we have to
|
|
|
|
# add the virtual fields separately from the topmost call. If we
|
|
|
|
# did this recursively similar to local_fields, we would get field
|
|
|
|
# instances with field.model != self.model.
|
|
|
|
if topmost_call:
|
|
|
|
fields.extend(
|
|
|
|
f for f in self.virtual_fields
|
|
|
|
)
|
2015-01-07 08:16:35 +08:00
|
|
|
|
2015-02-16 15:49:19 +08:00
|
|
|
# In order to avoid list manipulation. Always
|
|
|
|
# return a shallow copy of the results
|
|
|
|
fields = make_immutable_fields_list("get_fields()", fields)
|
2015-01-07 08:16:35 +08:00
|
|
|
|
|
|
|
# Store result into cache for later access
|
|
|
|
self._get_fields_cache[cache_key] = fields
|
|
|
|
return fields
|