2012-08-12 04:20:59 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-02-19 03:27:55 +08:00
|
|
|
import copy
|
2016-03-21 01:10:55 +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
|
2016-04-17 19:55:55 +08:00
|
|
|
from django.db.models import Manager
|
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
|
2016-10-09 02:09:49 +08:00
|
|
|
from django.db.models.fields.related import OneToOneField
|
2016-08-19 06:42:11 +08:00
|
|
|
from django.db.models.query_utils import PathInfo
|
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
|
2016-03-21 01:10:55 +08:00
|
|
|
from django.utils.deprecation import (
|
2016-11-24 06:04:10 +08:00
|
|
|
RemovedInDjango20Warning, RemovedInDjango21Warning,
|
|
|
|
warn_about_renamed_method,
|
2016-03-21 01:10:55 +08:00
|
|
|
)
|
2016-08-26 04:49:31 +08:00
|
|
|
from django.utils.encoding import force_text, python_2_unicode_compatible
|
2014-02-27 05:48:20 +08:00
|
|
|
from django.utils.functional import cached_property
|
2016-08-16 18:07:03 +08:00
|
|
|
from django.utils.text import camel_case_to_spaces, format_lazy
|
|
|
|
from django.utils.translation import override
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2016-03-21 01:10:55 +08:00
|
|
|
NOT_PROVIDED = object()
|
|
|
|
|
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
|
|
|
|
2016-03-29 06:33:29 +08:00
|
|
|
DEFAULT_NAMES = (
|
|
|
|
'verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
|
|
|
|
'unique_together', 'permissions', 'get_latest_by', 'order_with_respect_to',
|
|
|
|
'app_label', 'db_tablespace', 'abstract', 'managed', 'proxy', 'swappable',
|
|
|
|
'auto_created', 'index_together', 'apps', 'default_permissions',
|
|
|
|
'select_on_save', 'default_related_name', 'required_db_features',
|
2016-04-17 19:55:55 +08:00
|
|
|
'required_db_vendor', 'base_manager_name', 'default_manager_name',
|
2016-06-26 00:32:56 +08:00
|
|
|
'manager_inheritance_from_future', 'indexes',
|
2016-03-29 06:33:29 +08:00
|
|
|
)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2013-11-03 04:12:09 +08:00
|
|
|
|
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):
|
2016-04-17 19:55:55 +08:00
|
|
|
FORWARD_PROPERTIES = {
|
|
|
|
'fields', 'many_to_many', 'concrete_fields', 'local_concrete_fields',
|
|
|
|
'_forward_fields_map', 'managers', 'managers_map', 'base_manager',
|
|
|
|
'default_manager',
|
|
|
|
}
|
2015-11-13 21:37:31 +08:00
|
|
|
REVERSE_PROPERTIES = {'related_objects', 'fields_map', '_relation_tree'}
|
2015-01-07 08:16:35 +08:00
|
|
|
|
2015-11-17 13:33:18 +08:00
|
|
|
default_apps = apps
|
|
|
|
|
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 = {}
|
2013-12-31 23:13:40 +08:00
|
|
|
self.local_fields = []
|
|
|
|
self.local_many_to_many = []
|
2016-03-21 01:10:55 +08:00
|
|
|
self.private_fields = []
|
2016-04-17 19:55:55 +08:00
|
|
|
self.manager_inheritance_from_future = False
|
2016-02-19 03:27:55 +08:00
|
|
|
self.local_managers = []
|
2016-04-17 19:55:55 +08:00
|
|
|
self.base_manager_name = None
|
|
|
|
self.default_manager_name = None
|
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
|
2016-06-20 23:50:05 +08:00
|
|
|
self.indexes = []
|
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.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
|
|
|
|
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.
|
2015-11-17 13:33:18 +08:00
|
|
|
self.apps = self.default_apps
|
2012-09-22 07:47:04 +08:00
|
|
|
|
2014-06-07 00:16:17 +08:00
|
|
|
self.default_related_name = None
|
|
|
|
|
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
|
|
|
|
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:
|
2016-08-16 18:07:03 +08:00
|
|
|
self.verbose_name_plural = format_lazy('{}s', self.verbose_name)
|
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:
|
2016-08-16 18:07:03 +08:00
|
|
|
self.verbose_name_plural = format_lazy('{}s', self.verbose_name)
|
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:
|
2016-09-17 21:29:14 +08:00
|
|
|
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, query))
|
2015-01-07 08:16:35 +08:00
|
|
|
|
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)
|
2016-04-23 00:59:41 +08:00
|
|
|
if not field.remote_field.parent_link:
|
|
|
|
warnings.warn(
|
|
|
|
'Add parent_link=True to %s as an implicit link is '
|
|
|
|
'deprecated.' % field, RemovedInDjango20Warning
|
|
|
|
)
|
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:
|
2016-03-29 06:33:29 +08:00
|
|
|
auto = AutoField(verbose_name='ID', primary_key=True, auto_created=True)
|
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
|
|
|
model.add_to_class('id', auto)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2016-02-19 03:27:55 +08:00
|
|
|
def add_manager(self, manager):
|
|
|
|
self.local_managers.append(manager)
|
|
|
|
self._expire_cache()
|
|
|
|
|
2016-03-21 01:10:55 +08:00
|
|
|
def add_field(self, field, private=False, virtual=NOT_PROVIDED):
|
|
|
|
if virtual is not NOT_PROVIDED:
|
|
|
|
warnings.warn(
|
|
|
|
"The `virtual` argument of Options.add_field() has been renamed to `private`.",
|
|
|
|
RemovedInDjango20Warning, stacklevel=2
|
|
|
|
)
|
|
|
|
private = virtual
|
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.
|
2016-03-21 01:10:55 +08:00
|
|
|
if private:
|
|
|
|
self.private_fields.append(field)
|
2015-01-07 08:16:35 +08:00
|
|
|
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
|
2016-10-09 02:09:49 +08:00
|
|
|
# If the field is a OneToOneField and it's been marked as PK, then
|
|
|
|
# this is a multi-table inheritance PK. It needs to be serialized
|
|
|
|
# to relate the subclass instance to the superclass instance.
|
|
|
|
if not isinstance(field, OneToOneField):
|
|
|
|
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):
|
2016-08-26 04:49:31 +08:00
|
|
|
return "%s.%s" % (self.app_label, 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-08-22 21:40:34 +08:00
|
|
|
if '%s.%s' % (swapped_label, swapped_object.lower()) != 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
|
|
|
|
|
2016-02-19 03:27:55 +08:00
|
|
|
@cached_property
|
|
|
|
def managers(self):
|
|
|
|
managers = []
|
2016-08-19 02:24:45 +08:00
|
|
|
seen_managers = set()
|
2016-02-19 03:27:55 +08:00
|
|
|
bases = (b for b in self.model.mro() if hasattr(b, '_meta'))
|
|
|
|
for depth, base in enumerate(bases):
|
|
|
|
for manager in base._meta.local_managers:
|
2016-08-19 02:24:45 +08:00
|
|
|
if manager.name in seen_managers:
|
|
|
|
continue
|
|
|
|
|
2016-02-19 03:27:55 +08:00
|
|
|
manager = copy.copy(manager)
|
|
|
|
manager.model = self.model
|
2016-08-19 02:24:45 +08:00
|
|
|
seen_managers.add(manager.name)
|
2016-02-19 03:27:55 +08:00
|
|
|
managers.append((depth, manager.creation_counter, manager))
|
|
|
|
|
2016-04-17 19:55:55 +08:00
|
|
|
# Used for deprecation of legacy manager inheritance,
|
|
|
|
# remove afterwards. (RemovedInDjango20Warning)
|
|
|
|
manager._originating_model = base
|
|
|
|
|
2016-02-19 03:27:55 +08:00
|
|
|
return make_immutable_fields_list(
|
|
|
|
"managers",
|
|
|
|
(m[2] for m in sorted(managers)),
|
|
|
|
)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def managers_map(self):
|
2016-08-19 02:24:45 +08:00
|
|
|
return {manager.name: manager for manager in self.managers}
|
2016-02-19 03:27:55 +08:00
|
|
|
|
2016-04-17 19:55:55 +08:00
|
|
|
@cached_property
|
|
|
|
def base_manager(self):
|
|
|
|
base_manager_name = self.base_manager_name
|
|
|
|
if not base_manager_name:
|
|
|
|
# Get the first parent's base_manager_name if there's one.
|
|
|
|
for parent in self.model.mro()[1:]:
|
|
|
|
if hasattr(parent, '_meta'):
|
|
|
|
if parent._base_manager.name != '_base_manager':
|
|
|
|
base_manager_name = parent._base_manager.name
|
|
|
|
break
|
|
|
|
|
|
|
|
if base_manager_name:
|
|
|
|
try:
|
|
|
|
return self.managers_map[base_manager_name]
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError(
|
|
|
|
"%s has no manager named %r" % (
|
|
|
|
self.object_name,
|
|
|
|
base_manager_name,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Deprecation shim for `use_for_related_fields`.
|
|
|
|
for i, base_manager_class in enumerate(self.default_manager.__class__.mro()):
|
|
|
|
if getattr(base_manager_class, 'use_for_related_fields', False):
|
|
|
|
if not getattr(base_manager_class, 'silence_use_for_related_fields_deprecation', False):
|
|
|
|
warnings.warn(
|
|
|
|
"use_for_related_fields is deprecated, instead "
|
|
|
|
"set Meta.base_manager_name on '{}'.".format(self.model._meta.label),
|
|
|
|
RemovedInDjango20Warning, 2
|
|
|
|
)
|
|
|
|
|
|
|
|
if i == 0:
|
|
|
|
manager = self.default_manager
|
|
|
|
else:
|
|
|
|
manager = base_manager_class()
|
|
|
|
manager.name = '_base_manager'
|
|
|
|
manager.model = self.model
|
|
|
|
|
|
|
|
return manager
|
|
|
|
|
|
|
|
manager = Manager()
|
|
|
|
manager.name = '_base_manager'
|
|
|
|
manager.model = self.model
|
|
|
|
manager.auto_created = True
|
|
|
|
return manager
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def default_manager(self):
|
|
|
|
default_manager_name = self.default_manager_name
|
|
|
|
if not default_manager_name and not self.local_managers:
|
|
|
|
# Get the first parent's default_manager_name if there's one.
|
|
|
|
for parent in self.model.mro()[1:]:
|
|
|
|
if hasattr(parent, '_meta'):
|
|
|
|
default_manager_name = parent._meta.default_manager_name
|
|
|
|
break
|
|
|
|
|
|
|
|
if default_manager_name:
|
|
|
|
try:
|
|
|
|
return self.managers_map[default_manager_name]
|
|
|
|
except KeyError:
|
|
|
|
raise ValueError(
|
|
|
|
"%s has no manager named %r" % (
|
|
|
|
self.object_name,
|
|
|
|
default_manager_name,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.managers:
|
|
|
|
return self.managers[0]
|
|
|
|
|
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
|
2016-03-21 01:10:55 +08:00
|
|
|
# fields that are not private or with a m2m cardinality. Therefore we
|
2015-01-07 08:16:35 +08:00
|
|
|
# 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.
|
2016-01-24 00:47:07 +08:00
|
|
|
def is_not_an_m2m_field(f):
|
|
|
|
return not (f.is_relation and f.many_to_many)
|
|
|
|
|
|
|
|
def is_not_a_generic_relation(f):
|
|
|
|
return not (f.is_relation and f.one_to_many)
|
|
|
|
|
|
|
|
def is_not_a_generic_foreign_key(f):
|
|
|
|
return not (
|
|
|
|
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",
|
2016-04-04 08:37:32 +08:00
|
|
|
(f for f in self._get_fields(reverse=False)
|
2016-03-29 06:33:29 +08:00
|
|
|
if is_not_an_m2m_field(f) and is_not_a_generic_relation(f) and is_not_a_generic_foreign_key(f))
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
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
|
|
|
|
2016-03-21 01:10:55 +08:00
|
|
|
@property
|
|
|
|
@warn_about_renamed_method(
|
|
|
|
'Options', 'virtual_fields', 'private_fields',
|
|
|
|
RemovedInDjango20Warning
|
|
|
|
)
|
|
|
|
def virtual_fields(self):
|
|
|
|
return self.private_fields
|
|
|
|
|
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
|
|
|
@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",
|
2016-03-29 06:33:29 +08:00
|
|
|
(f for f in self._get_fields(reverse=False) if f.is_relation and f.many_to_many)
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
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",
|
2016-03-29 06:33:29 +08:00
|
|
|
(obj for obj in all_related_fields if not obj.hidden or obj.field.many_to_many)
|
2015-01-07 08:16:35 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
2015-08-17 20:50:34 +08:00
|
|
|
def get_field(self, field_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
|
|
|
"""
|
2015-08-17 20:50:34 +08:00
|
|
|
Return a field instance given the name of a forward or reverse 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
|
|
|
"""
|
|
|
|
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.
|
2015-08-17 20:50:34 +08:00
|
|
|
return self._forward_fields_map[field_name]
|
2015-01-07 08:16:35 +08:00
|
|
|
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(
|
2016-09-17 21:29:14 +08:00
|
|
|
"%s has no field named '%s'. 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:
|
|
|
|
# Retrieve field instance by name from cached or just-computed
|
|
|
|
# field map.
|
|
|
|
return self.fields_map[field_name]
|
|
|
|
except KeyError:
|
2016-09-17 21:29:14 +08:00
|
|
|
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
|
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
|
|
|
def get_base_chain(self, model):
|
|
|
|
"""
|
2015-07-25 23:16:27 +08:00
|
|
|
Return a list of parent classes leading to `model` (ordered from
|
|
|
|
closest to most distant ancestor). This has to handle the case where
|
|
|
|
`model` is 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:
|
2015-07-25 23:16:27 +08:00
|
|
|
return []
|
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
|
2015-07-25 23:16:27 +08:00
|
|
|
return []
|
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
|
|
|
|
2016-08-19 06:42:11 +08:00
|
|
|
def get_path_to_parent(self, parent):
|
|
|
|
"""
|
|
|
|
Return a list of PathInfos containing the path from the current
|
|
|
|
model to the parent model, or an empty list if parent is not a
|
|
|
|
parent of the current model.
|
|
|
|
"""
|
|
|
|
if self.model is parent:
|
|
|
|
return []
|
|
|
|
# Skip the chain of proxy to the concrete proxied model.
|
|
|
|
proxied_model = self.concrete_model
|
|
|
|
path = []
|
|
|
|
opts = self
|
|
|
|
for int_model in self.get_base_chain(parent):
|
|
|
|
if int_model is proxied_model:
|
|
|
|
opts = int_model._meta
|
|
|
|
else:
|
|
|
|
final_field = opts.parents[int_model]
|
|
|
|
targets = (final_field.remote_field.get_related_field(),)
|
|
|
|
opts = int_model._meta
|
|
|
|
path.append(PathInfo(final_field.model._meta, opts, targets, final_field, False, True))
|
|
|
|
return path
|
|
|
|
|
|
|
|
def get_path_from_parent(self, parent):
|
|
|
|
"""
|
|
|
|
Return a list of PathInfos containing the path from the parent
|
|
|
|
model to the current model, or an empty list if parent is not a
|
|
|
|
parent of the current model.
|
|
|
|
"""
|
|
|
|
if self.model is parent:
|
|
|
|
return []
|
|
|
|
model = self.concrete_model
|
|
|
|
# Get a reversed base chain including both the current and parent
|
|
|
|
# models.
|
|
|
|
chain = model._meta.get_base_chain(parent)
|
|
|
|
chain.reverse()
|
|
|
|
chain.append(model)
|
|
|
|
# Construct a list of the PathInfos between models in chain.
|
|
|
|
path = []
|
|
|
|
for i, ancestor in enumerate(chain[:-1]):
|
|
|
|
child = chain[i + 1]
|
|
|
|
link = child._meta.get_ancestor_link(ancestor)
|
|
|
|
path.extend(link.get_reverse_path_info())
|
|
|
|
return path
|
|
|
|
|
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-10-02 02:57:58 +08:00
|
|
|
opts = model._meta
|
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.
|
2015-10-02 02:57:58 +08:00
|
|
|
if opts.abstract:
|
2015-02-16 15:49:19 +08:00
|
|
|
continue
|
2015-01-07 08:16:35 +08:00
|
|
|
fields_with_relations = (
|
2015-10-02 02:57:58 +08:00
|
|
|
f for f in opts._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):
|
2015-10-08 03:29:20 +08:00
|
|
|
related_objects_graph[f.remote_field.model._meta.concrete_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__.
|
2015-10-08 03:29:20 +08:00
|
|
|
related_objects = related_objects_graph[model._meta.concrete_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.
|
|
|
|
if forward:
|
2015-11-13 21:37:31 +08:00
|
|
|
for cache_key in self.FORWARD_PROPERTIES:
|
|
|
|
if cache_key in self.__dict__:
|
|
|
|
delattr(self, cache_key)
|
2015-01-07 08:16:35 +08:00
|
|
|
if reverse and not self.abstract:
|
2015-11-13 21:37:31 +08:00
|
|
|
for cache_key in self.REVERSE_PROPERTIES:
|
|
|
|
if cache_key in self.__dict__:
|
|
|
|
delattr(self, cache_key)
|
2015-01-07 08:16:35 +08:00
|
|
|
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):
|
2015-10-08 03:29:20 +08:00
|
|
|
if getattr(obj, 'parent_link', False) and obj.model != self.concrete_model:
|
2015-02-16 15:49:19 +08:00
|
|
|
continue
|
|
|
|
fields.append(obj)
|
2015-10-08 03:29:20 +08:00
|
|
|
if reverse and not self.proxy:
|
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
|
|
|
)
|
2016-03-21 01:10:55 +08:00
|
|
|
# Private fields are recopied to each child model, and they get a
|
2015-02-16 15:49:19 +08:00
|
|
|
# different model as field.model in each child. Hence we have to
|
2016-03-21 01:10:55 +08:00
|
|
|
# add the private fields separately from the topmost call. If we
|
2015-02-16 15:49:19 +08:00
|
|
|
# did this recursively similar to local_fields, we would get field
|
|
|
|
# instances with field.model != self.model.
|
|
|
|
if topmost_call:
|
|
|
|
fields.extend(
|
2016-03-21 01:10:55 +08:00
|
|
|
f for f in self.private_fields
|
2015-02-16 15:49:19 +08:00
|
|
|
)
|
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
|
2016-11-24 06:04:10 +08:00
|
|
|
|
|
|
|
@property
|
|
|
|
def has_auto_field(self):
|
|
|
|
warnings.warn(
|
|
|
|
'Model._meta.has_auto_field is deprecated in favor of checking if '
|
|
|
|
'Model._meta.auto_field is not None.',
|
|
|
|
RemovedInDjango21Warning, stacklevel=2
|
|
|
|
)
|
|
|
|
return self.auto_field is not None
|
|
|
|
|
|
|
|
@has_auto_field.setter
|
|
|
|
def has_auto_field(self, value):
|
|
|
|
pass
|
2016-12-16 02:42:44 +08:00
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def _property_names(self):
|
|
|
|
"""
|
|
|
|
Return a set of the names of the properties defined on the model.
|
|
|
|
Internal helper for model initialization.
|
|
|
|
"""
|
|
|
|
return frozenset({
|
|
|
|
attr for attr in
|
|
|
|
dir(self.model) if isinstance(getattr(self.model, attr), property)
|
|
|
|
})
|