测试gitnore
This commit is contained in:
@@ -33,7 +33,7 @@ class BaseManager:
|
||||
|
||||
def __str__(self):
|
||||
"""Return "app_label.model_label.manager_name"."""
|
||||
return "%s.%s" % (self.model._meta.label, self.name)
|
||||
return '%s.%s' % (self.model._meta.label, self.name)
|
||||
|
||||
def __class_getitem__(cls, *args, **kwargs):
|
||||
return cls
|
||||
@@ -46,12 +46,12 @@ class BaseManager:
|
||||
Raise a ValueError if the manager is dynamically generated.
|
||||
"""
|
||||
qs_class = self._queryset_class
|
||||
if getattr(self, "_built_with_as_manager", False):
|
||||
if getattr(self, '_built_with_as_manager', False):
|
||||
# using MyQuerySet.as_manager()
|
||||
return (
|
||||
True, # as_manager
|
||||
None, # manager_class
|
||||
"%s.%s" % (qs_class.__module__, qs_class.__name__), # qs_class
|
||||
'%s.%s' % (qs_class.__module__, qs_class.__name__), # qs_class
|
||||
None, # args
|
||||
None, # kwargs
|
||||
)
|
||||
@@ -69,7 +69,7 @@ class BaseManager:
|
||||
)
|
||||
return (
|
||||
False, # as_manager
|
||||
"%s.%s" % (module_name, name), # manager_class
|
||||
'%s.%s' % (module_name, name), # manager_class
|
||||
None, # qs_class
|
||||
self._constructor_args[0], # args
|
||||
self._constructor_args[1], # kwargs
|
||||
@@ -83,22 +83,18 @@ class BaseManager:
|
||||
def create_method(name, method):
|
||||
def manager_method(self, *args, **kwargs):
|
||||
return getattr(self.get_queryset(), name)(*args, **kwargs)
|
||||
|
||||
manager_method.__name__ = method.__name__
|
||||
manager_method.__doc__ = method.__doc__
|
||||
return manager_method
|
||||
|
||||
new_methods = {}
|
||||
for name, method in inspect.getmembers(
|
||||
queryset_class, predicate=inspect.isfunction
|
||||
):
|
||||
for name, method in inspect.getmembers(queryset_class, predicate=inspect.isfunction):
|
||||
# Only copy missing methods.
|
||||
if hasattr(cls, name):
|
||||
continue
|
||||
# Only copy public methods or methods with the attribute
|
||||
# queryset_only=False.
|
||||
queryset_only = getattr(method, "queryset_only", None)
|
||||
if queryset_only or (queryset_only is None and name.startswith("_")):
|
||||
# Only copy public methods or methods with the attribute `queryset_only=False`.
|
||||
queryset_only = getattr(method, 'queryset_only', None)
|
||||
if queryset_only or (queryset_only is None and name.startswith('_')):
|
||||
continue
|
||||
# Copy the method onto the manager.
|
||||
new_methods[name] = create_method(name, method)
|
||||
@@ -107,15 +103,11 @@ class BaseManager:
|
||||
@classmethod
|
||||
def from_queryset(cls, queryset_class, class_name=None):
|
||||
if class_name is None:
|
||||
class_name = "%sFrom%s" % (cls.__name__, queryset_class.__name__)
|
||||
return type(
|
||||
class_name,
|
||||
(cls,),
|
||||
{
|
||||
"_queryset_class": queryset_class,
|
||||
**cls._get_queryset_methods(queryset_class),
|
||||
},
|
||||
)
|
||||
class_name = '%sFrom%s' % (cls.__name__, queryset_class.__name__)
|
||||
return type(class_name, (cls,), {
|
||||
'_queryset_class': queryset_class,
|
||||
**cls._get_queryset_methods(queryset_class),
|
||||
})
|
||||
|
||||
def contribute_to_class(self, cls, name):
|
||||
self.name = self.name or name
|
||||
@@ -165,8 +157,8 @@ class BaseManager:
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
isinstance(other, self.__class__)
|
||||
and self._constructor_args == other._constructor_args
|
||||
isinstance(other, self.__class__) and
|
||||
self._constructor_args == other._constructor_args
|
||||
)
|
||||
|
||||
def __hash__(self):
|
||||
@@ -178,24 +170,22 @@ class Manager(BaseManager.from_queryset(QuerySet)):
|
||||
|
||||
|
||||
class ManagerDescriptor:
|
||||
|
||||
def __init__(self, manager):
|
||||
self.manager = manager
|
||||
|
||||
def __get__(self, instance, cls=None):
|
||||
if instance is not None:
|
||||
raise AttributeError(
|
||||
"Manager isn't accessible via %s instances" % cls.__name__
|
||||
)
|
||||
raise AttributeError("Manager isn't accessible via %s instances" % cls.__name__)
|
||||
|
||||
if cls._meta.abstract:
|
||||
raise AttributeError(
|
||||
"Manager isn't available; %s is abstract" % (cls._meta.object_name,)
|
||||
)
|
||||
raise AttributeError("Manager isn't available; %s is abstract" % (
|
||||
cls._meta.object_name,
|
||||
))
|
||||
|
||||
if cls._meta.swapped:
|
||||
raise AttributeError(
|
||||
"Manager isn't available; '%s' has been swapped for '%s'"
|
||||
% (
|
||||
"Manager isn't available; '%s' has been swapped for '%s'" % (
|
||||
cls._meta.label,
|
||||
cls._meta.swapped,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user