2013-05-04 17:53:12 +08:00
|
|
|
from functools import wraps
|
2013-12-16 18:34:10 +08:00
|
|
|
import sys
|
|
|
|
import warnings
|
2013-05-04 17:53:12 +08:00
|
|
|
|
2013-12-12 04:44:27 +08:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured # NOQA
|
2013-11-07 01:25:05 +08:00
|
|
|
from django.db.models.query import Q, QuerySet, Prefetch # NOQA
|
2013-12-25 21:13:18 +08:00
|
|
|
from django.db.models.expressions import ExpressionNode, F, Value, Func # NOQA
|
2013-10-18 19:25:30 +08:00
|
|
|
from django.db.models.manager import Manager # NOQA
|
|
|
|
from django.db.models.base import Model # NOQA
|
|
|
|
from django.db.models.aggregates import * # NOQA
|
|
|
|
from django.db.models.fields import * # NOQA
|
|
|
|
from django.db.models.fields.subclassing import SubfieldBase # NOQA
|
2013-11-03 05:02:56 +08:00
|
|
|
from django.db.models.fields.files import FileField, ImageField # NOQA
|
2013-10-18 19:25:30 +08:00
|
|
|
from django.db.models.fields.related import ( # NOQA
|
|
|
|
ForeignKey, ForeignObject, OneToOneField, ManyToManyField,
|
|
|
|
ManyToOneRel, ManyToManyRel, OneToOneRel)
|
2013-12-07 03:22:53 +08:00
|
|
|
from django.db.models.fields.proxy import OrderWrt # NOQA
|
2013-10-18 19:25:30 +08:00
|
|
|
from django.db.models.deletion import ( # NOQA
|
|
|
|
CASCADE, PROTECT, SET, SET_NULL, SET_DEFAULT, DO_NOTHING, ProtectedError)
|
2014-01-18 17:09:43 +08:00
|
|
|
from django.db.models.lookups import Lookup, Transform # NOQA
|
2013-10-18 19:25:30 +08:00
|
|
|
from django.db.models import signals # NOQA
|
2014-02-27 05:48:20 +08:00
|
|
|
from django.utils.deprecation import RemovedInDjango19Warning
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
|
2006-07-28 10:09:38 +08:00
|
|
|
def permalink(func):
|
2007-07-16 21:47:43 +08:00
|
|
|
"""
|
|
|
|
Decorator that calls urlresolvers.reverse() to return a URL using
|
|
|
|
parameters returned by the decorated function "func".
|
|
|
|
|
|
|
|
"func" should be a function that returns a tuple in one of the
|
|
|
|
following formats:
|
|
|
|
(viewname, viewargs)
|
|
|
|
(viewname, viewargs, viewkwargs)
|
|
|
|
"""
|
2006-07-28 10:09:38 +08:00
|
|
|
from django.core.urlresolvers import reverse
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2011-03-14 13:22:39 +08:00
|
|
|
@wraps(func)
|
2006-07-28 10:09:38 +08:00
|
|
|
def inner(*args, **kwargs):
|
|
|
|
bits = func(*args, **kwargs)
|
2006-08-09 22:40:29 +08:00
|
|
|
return reverse(bits[0], None, *bits[1:3])
|
2006-07-28 10:09:38 +08:00
|
|
|
return inner
|
2013-12-16 18:34:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Deprecated aliases for functions were exposed in this module.
|
|
|
|
|
|
|
|
def make_alias(function_name):
|
|
|
|
# Close function_name.
|
|
|
|
def alias(*args, **kwargs):
|
|
|
|
warnings.warn(
|
|
|
|
"django.db.models.%s is deprecated." % function_name,
|
2014-02-27 05:48:20 +08:00
|
|
|
RemovedInDjango19Warning, stacklevel=2)
|
2013-12-16 18:34:10 +08:00
|
|
|
# This raises a second warning.
|
|
|
|
from . import loading
|
|
|
|
return getattr(loading, function_name)(*args, **kwargs)
|
|
|
|
alias.__name__ = function_name
|
|
|
|
return alias
|
|
|
|
|
|
|
|
this_module = sys.modules['django.db.models']
|
|
|
|
|
|
|
|
for function_name in ('get_apps', 'get_app_path', 'get_app_paths', 'get_app',
|
|
|
|
'get_models', 'get_model', 'register_models'):
|
|
|
|
setattr(this_module, function_name, make_alias(function_name))
|
|
|
|
|
|
|
|
del this_module, make_alias, function_name
|