Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
GEOSGeometry.centroid | (self) |
The centroid is equal to the centroid of the set of component Geometries
of highest dimension (since the lower-dimension geometries contribute zero
"weight" to the centroid).
|
The centroid is equal to the centroid of the set of component Geometries
of highest dimension (since the lower-dimension geometries contribute zero
"weight" to the centroid).
| def centroid(self):
"""
The centroid is equal to the centroid of the set of component Geometries
of highest dimension (since the lower-dimension geometries contribute zero
"weight" to the centroid).
"""
return self._topology(capi.geos_centroid(self.ptr)) | [
"def",
"centroid",
"(",
"self",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_centroid",
"(",
"self",
".",
"ptr",
")",
")"
] | [
546,
4
] | [
552,
59
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.convex_hull | (self) |
Returns the smallest convex Polygon that contains all the points
in the Geometry.
|
Returns the smallest convex Polygon that contains all the points
in the Geometry.
| def convex_hull(self):
"""
Returns the smallest convex Polygon that contains all the points
in the Geometry.
"""
return self._topology(capi.geos_convexhull(self.ptr)) | [
"def",
"convex_hull",
"(",
"self",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_convexhull",
"(",
"self",
".",
"ptr",
")",
")"
] | [
555,
4
] | [
560,
61
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.difference | (self, other) |
Returns a Geometry representing the points making up this Geometry
that do not make up other.
|
Returns a Geometry representing the points making up this Geometry
that do not make up other.
| def difference(self, other):
"""
Returns a Geometry representing the points making up this Geometry
that do not make up other.
"""
return self._topology(capi.geos_difference(self.ptr, other.ptr)) | [
"def",
"difference",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_difference",
"(",
"self",
".",
"ptr",
",",
"other",
".",
"ptr",
")",
")"
] | [
562,
4
] | [
567,
72
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.envelope | (self) | Return the envelope for this geometry (a polygon). | Return the envelope for this geometry (a polygon). | def envelope(self):
"Return the envelope for this geometry (a polygon)."
return self._topology(capi.geos_envelope(self.ptr)) | [
"def",
"envelope",
"(",
"self",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_envelope",
"(",
"self",
".",
"ptr",
")",
")"
] | [
570,
4
] | [
572,
59
] | python | en | ['en', 'en', 'en'] | True |
GEOSGeometry.intersection | (self, other) | Returns a Geometry representing the points shared by this Geometry and other. | Returns a Geometry representing the points shared by this Geometry and other. | def intersection(self, other):
"Returns a Geometry representing the points shared by this Geometry and other."
return self._topology(capi.geos_intersection(self.ptr, other.ptr)) | [
"def",
"intersection",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_intersection",
"(",
"self",
".",
"ptr",
",",
"other",
".",
"ptr",
")",
")"
] | [
584,
4
] | [
586,
74
] | python | en | ['en', 'en', 'en'] | True |
GEOSGeometry.point_on_surface | (self) | Computes an interior point of this Geometry. | Computes an interior point of this Geometry. | def point_on_surface(self):
"Computes an interior point of this Geometry."
return self._topology(capi.geos_pointonsurface(self.ptr)) | [
"def",
"point_on_surface",
"(",
"self",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_pointonsurface",
"(",
"self",
".",
"ptr",
")",
")"
] | [
589,
4
] | [
591,
65
] | python | en | ['en', 'en', 'en'] | True |
GEOSGeometry.relate | (self, other) | Returns the DE-9IM intersection matrix for this Geometry and the other. | Returns the DE-9IM intersection matrix for this Geometry and the other. | def relate(self, other):
"Returns the DE-9IM intersection matrix for this Geometry and the other."
return capi.geos_relate(self.ptr, other.ptr).decode() | [
"def",
"relate",
"(",
"self",
",",
"other",
")",
":",
"return",
"capi",
".",
"geos_relate",
"(",
"self",
".",
"ptr",
",",
"other",
".",
"ptr",
")",
".",
"decode",
"(",
")"
] | [
607,
4
] | [
609,
61
] | python | en | ['en', 'en', 'en'] | True |
GEOSGeometry.simplify | (self, tolerance=0.0, preserve_topology=False) |
Returns the Geometry, simplified using the Douglas-Peucker algorithm
to the specified tolerance (higher tolerance => less points). If no
tolerance provided, defaults to 0.
By default, this function does not preserve topology - e.g. polygons can
be split, collapse to lines or d... |
Returns the Geometry, simplified using the Douglas-Peucker algorithm
to the specified tolerance (higher tolerance => less points). If no
tolerance provided, defaults to 0. | def simplify(self, tolerance=0.0, preserve_topology=False):
"""
Returns the Geometry, simplified using the Douglas-Peucker algorithm
to the specified tolerance (higher tolerance => less points). If no
tolerance provided, defaults to 0.
By default, this function does not preserv... | [
"def",
"simplify",
"(",
"self",
",",
"tolerance",
"=",
"0.0",
",",
"preserve_topology",
"=",
"False",
")",
":",
"if",
"preserve_topology",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_preservesimplify",
"(",
"self",
".",
"ptr",
",",
"to... | [
611,
4
] | [
626,
74
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.sym_difference | (self, other) |
Returns a set combining the points in this Geometry not in other,
and the points in other not in this Geometry.
|
Returns a set combining the points in this Geometry not in other,
and the points in other not in this Geometry.
| def sym_difference(self, other):
"""
Returns a set combining the points in this Geometry not in other,
and the points in other not in this Geometry.
"""
return self._topology(capi.geos_symdifference(self.ptr, other.ptr)) | [
"def",
"sym_difference",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_symdifference",
"(",
"self",
".",
"ptr",
",",
"other",
".",
"ptr",
")",
")"
] | [
628,
4
] | [
633,
75
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.union | (self, other) | Returns a Geometry representing all the points in this Geometry and other. | Returns a Geometry representing all the points in this Geometry and other. | def union(self, other):
"Returns a Geometry representing all the points in this Geometry and other."
return self._topology(capi.geos_union(self.ptr, other.ptr)) | [
"def",
"union",
"(",
"self",
",",
"other",
")",
":",
"return",
"self",
".",
"_topology",
"(",
"capi",
".",
"geos_union",
"(",
"self",
".",
"ptr",
",",
"other",
".",
"ptr",
")",
")"
] | [
635,
4
] | [
637,
67
] | python | en | ['en', 'en', 'en'] | True |
GEOSGeometry.area | (self) | Returns the area of the Geometry. | Returns the area of the Geometry. | def area(self):
"Returns the area of the Geometry."
return capi.geos_area(self.ptr, byref(c_double())) | [
"def",
"area",
"(",
"self",
")",
":",
"return",
"capi",
".",
"geos_area",
"(",
"self",
".",
"ptr",
",",
"byref",
"(",
"c_double",
"(",
")",
")",
")"
] | [
641,
4
] | [
643,
58
] | python | en | ['en', 'en', 'en'] | True |
GEOSGeometry.distance | (self, other) |
Returns the distance between the closest points on this Geometry
and the other. Units will be in those of the coordinate system of
the Geometry.
|
Returns the distance between the closest points on this Geometry
and the other. Units will be in those of the coordinate system of
the Geometry.
| def distance(self, other):
"""
Returns the distance between the closest points on this Geometry
and the other. Units will be in those of the coordinate system of
the Geometry.
"""
if not isinstance(other, GEOSGeometry):
raise TypeError('distance() works only o... | [
"def",
"distance",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"isinstance",
"(",
"other",
",",
"GEOSGeometry",
")",
":",
"raise",
"TypeError",
"(",
"'distance() works only on other GEOS Geometries.'",
")",
"return",
"capi",
".",
"geos_distance",
"(",
"sel... | [
645,
4
] | [
653,
73
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.extent | (self) |
Returns the extent of this geometry as a 4-tuple, consisting of
(xmin, ymin, xmax, ymax).
|
Returns the extent of this geometry as a 4-tuple, consisting of
(xmin, ymin, xmax, ymax).
| def extent(self):
"""
Returns the extent of this geometry as a 4-tuple, consisting of
(xmin, ymin, xmax, ymax).
"""
env = self.envelope
if isinstance(env, Point):
xmin, ymin = env.tuple
xmax, ymax = xmin, ymin
else:
xmin, ymin =... | [
"def",
"extent",
"(",
"self",
")",
":",
"env",
"=",
"self",
".",
"envelope",
"if",
"isinstance",
"(",
"env",
",",
"Point",
")",
":",
"xmin",
",",
"ymin",
"=",
"env",
".",
"tuple",
"xmax",
",",
"ymax",
"=",
"xmin",
",",
"ymin",
"else",
":",
"xmin"... | [
656,
4
] | [
668,
39
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.length | (self) |
Returns the length of this Geometry (e.g., 0 for point, or the
circumference of a Polygon).
|
Returns the length of this Geometry (e.g., 0 for point, or the
circumference of a Polygon).
| def length(self):
"""
Returns the length of this Geometry (e.g., 0 for point, or the
circumference of a Polygon).
"""
return capi.geos_length(self.ptr, byref(c_double())) | [
"def",
"length",
"(",
"self",
")",
":",
"return",
"capi",
".",
"geos_length",
"(",
"self",
".",
"ptr",
",",
"byref",
"(",
"c_double",
"(",
")",
")",
")"
] | [
671,
4
] | [
676,
60
] | python | en | ['en', 'error', 'th'] | False |
GEOSGeometry.clone | (self) | Clones this Geometry. | Clones this Geometry. | def clone(self):
"Clones this Geometry."
return GEOSGeometry(capi.geom_clone(self.ptr), srid=self.srid) | [
"def",
"clone",
"(",
"self",
")",
":",
"return",
"GEOSGeometry",
"(",
"capi",
".",
"geom_clone",
"(",
"self",
".",
"ptr",
")",
",",
"srid",
"=",
"self",
".",
"srid",
")"
] | [
678,
4
] | [
680,
70
] | python | en | ['en', 'sr', 'en'] | True |
matches_patterns | (path, patterns=None) |
Return True or False depending on whether the ``path`` should be
ignored (if it matches any pattern in ``ignore_patterns``).
|
Return True or False depending on whether the ``path`` should be
ignored (if it matches any pattern in ``ignore_patterns``).
| def matches_patterns(path, patterns=None):
"""
Return True or False depending on whether the ``path`` should be
ignored (if it matches any pattern in ``ignore_patterns``).
"""
if patterns is None:
patterns = []
for pattern in patterns:
if fnmatch.fnmatchcase(path, pattern):
... | [
"def",
"matches_patterns",
"(",
"path",
",",
"patterns",
"=",
"None",
")",
":",
"if",
"patterns",
"is",
"None",
":",
"patterns",
"=",
"[",
"]",
"for",
"pattern",
"in",
"patterns",
":",
"if",
"fnmatch",
".",
"fnmatchcase",
"(",
"path",
",",
"pattern",
"... | [
6,
0
] | [
16,
16
] | python | en | ['en', 'error', 'th'] | False |
get_files | (storage, ignore_patterns=None, location='') |
Recursively walk the storage directories yielding the paths
of all files that should be copied.
|
Recursively walk the storage directories yielding the paths
of all files that should be copied.
| def get_files(storage, ignore_patterns=None, location=''):
"""
Recursively walk the storage directories yielding the paths
of all files that should be copied.
"""
if ignore_patterns is None:
ignore_patterns = []
directories, files = storage.listdir(location)
for fn in files:
... | [
"def",
"get_files",
"(",
"storage",
",",
"ignore_patterns",
"=",
"None",
",",
"location",
"=",
"''",
")",
":",
"if",
"ignore_patterns",
"is",
"None",
":",
"ignore_patterns",
"=",
"[",
"]",
"directories",
",",
"files",
"=",
"storage",
".",
"listdir",
"(",
... | [
19,
0
] | [
39,
20
] | python | en | ['en', 'error', 'th'] | False |
check_settings | (base_url=None) |
Checks if the staticfiles settings have sane values.
|
Checks if the staticfiles settings have sane values. | def check_settings(base_url=None):
"""
Checks if the staticfiles settings have sane values.
"""
if base_url is None:
base_url = settings.STATIC_URL
if not base_url:
raise ImproperlyConfigured(
"You're using the staticfiles app "
"without having set the requir... | [
"def",
"check_settings",
"(",
"base_url",
"=",
"None",
")",
":",
"if",
"base_url",
"is",
"None",
":",
"base_url",
"=",
"settings",
".",
"STATIC_URL",
"if",
"not",
"base_url",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"You're using the staticfiles app \"",
"\"wi... | [
42,
0
] | [
59,
73
] | python | en | ['en', 'error', 'th'] | False |
EmailBackend.send_messages | (self, messages) | Redirect messages to the dummy outbox | Redirect messages to the dummy outbox | def send_messages(self, messages):
"""Redirect messages to the dummy outbox"""
msg_count = 0
for message in messages: # .message() triggers header validation
message.message()
msg_count += 1
mail.outbox.extend(messages)
return msg_count | [
"def",
"send_messages",
"(",
"self",
",",
"messages",
")",
":",
"msg_count",
"=",
"0",
"for",
"message",
"in",
"messages",
":",
"# .message() triggers header validation",
"message",
".",
"message",
"(",
")",
"msg_count",
"+=",
"1",
"mail",
".",
"outbox",
".",
... | [
21,
4
] | [
28,
24
] | python | en | ['en', 'en', 'en'] | True |
maybe_load_model | (savedir, container) | Load model if present at the specified path. | Load model if present at the specified path. | def maybe_load_model(savedir, container):
"""Load model if present at the specified path."""
if savedir is None:
return
state_path = os.path.join(os.path.join(savedir, "training_state.pkl.zip"))
if container is not None:
logger.log("Attempting to download model from Azure")
foun... | [
"def",
"maybe_load_model",
"(",
"savedir",
",",
"container",
")",
":",
"if",
"savedir",
"is",
"None",
":",
"return",
"state_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"join",
"(",
"savedir",
",",
"\"training_state.pkl.zip\"",
... | [
186,
0
] | [
206,
20
] | python | en | ['en', 'en', 'en'] | True |
register_ipaddress | (conn_or_curs=None) |
Register conversion support between `ipaddress` objects and `network types`__.
:param conn_or_curs: the scope where to register the type casters.
If `!None` register them globally.
After the function is called, PostgreSQL :sql:`inet` values will be
converted into `~ipaddress.IPv4Interface` or... |
Register conversion support between `ipaddress` objects and `network types`__. | def register_ipaddress(conn_or_curs=None):
"""
Register conversion support between `ipaddress` objects and `network types`__.
:param conn_or_curs: the scope where to register the type casters.
If `!None` register them globally.
After the function is called, PostgreSQL :sql:`inet` values will b... | [
"def",
"register_ipaddress",
"(",
"conn_or_curs",
"=",
"None",
")",
":",
"global",
"ipaddress",
"import",
"ipaddress",
"global",
"_casters",
"if",
"_casters",
"is",
"None",
":",
"_casters",
"=",
"_make_casters",
"(",
")",
"for",
"c",
"in",
"_casters",
":",
"... | [
37,
0
] | [
63,
44
] | python | en | ['en', 'error', 'th'] | False |
rename_for_jekyll | (nb_path: Path, warnings: Set[Tuple[str, str]]=None) |
Return a Path's filename string appended with its modified time in YYYY-MM-DD format.
|
Return a Path's filename string appended with its modified time in YYYY-MM-DD format.
| def rename_for_jekyll(nb_path: Path, warnings: Set[Tuple[str, str]]=None) -> str:
"""
Return a Path's filename string appended with its modified time in YYYY-MM-DD format.
"""
assert nb_path.exists(), f'{nb_path} could not be found.'
# Checks if filename is compliant with Jekyll blog posts
if _... | [
"def",
"rename_for_jekyll",
"(",
"nb_path",
":",
"Path",
",",
"warnings",
":",
"Set",
"[",
"Tuple",
"[",
"str",
",",
"str",
"]",
"]",
"=",
"None",
")",
"->",
"str",
":",
"assert",
"nb_path",
".",
"exists",
"(",
")",
",",
"f'{nb_path} could not be found.'... | [
10,
0
] | [
28,
19
] | python | en | ['en', 'error', 'th'] | False |
Attack.construct_graph | (self, **kwargs) |
Constructs the graph required to run the attacks.
Is inherited from the attack class, is overloaded
to raise an error.
|
Constructs the graph required to run the attacks.
Is inherited from the attack class, is overloaded
to raise an error.
| def construct_graph(self, **kwargs):
"""
Constructs the graph required to run the attacks.
Is inherited from the attack class, is overloaded
to raise an error.
"""
error = "This method is not required for eager execution."
raise AttributeError(error) | [
"def",
"construct_graph",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"error",
"=",
"\"This method is not required for eager execution.\"",
"raise",
"AttributeError",
"(",
"error",
")"
] | [
48,
4
] | [
55,
35
] | python | en | ['en', 'error', 'th'] | False |
Attack.generate_np | (self, x_val, **kwargs) |
Generate adversarial examples and return them as a NumPy array.
:param x_val: A NumPy array with the original inputs.
:param **kwargs: optional parameters used by child classes.
:return: A NumPy array holding the adversarial examples.
|
Generate adversarial examples and return them as a NumPy array. | def generate_np(self, x_val, **kwargs):
"""
Generate adversarial examples and return them as a NumPy array.
:param x_val: A NumPy array with the original inputs.
:param **kwargs: optional parameters used by child classes.
:return: A NumPy array holding the adversarial examples.
... | [
"def",
"generate_np",
"(",
"self",
",",
"x_val",
",",
"*",
"*",
"kwargs",
")",
":",
"tfe",
"=",
"tf",
".",
"contrib",
".",
"eager",
"x",
"=",
"tfe",
".",
"Variable",
"(",
"x_val",
")",
"adv_x",
"=",
"self",
".",
"generate",
"(",
"x",
",",
"*",
... | [
57,
4
] | [
68,
28
] | python | en | ['en', 'error', 'th'] | False |
Attack.construct_variables | (self, kwargs) |
Construct the inputs to the attack graph.
Is inherited from the attack class, is overloaded
to raise an error.
|
Construct the inputs to the attack graph.
Is inherited from the attack class, is overloaded
to raise an error.
| def construct_variables(self, kwargs):
"""
Construct the inputs to the attack graph.
Is inherited from the attack class, is overloaded
to raise an error.
"""
error = "This method is not required for eager execution."
raise AttributeError(error) | [
"def",
"construct_variables",
"(",
"self",
",",
"kwargs",
")",
":",
"error",
"=",
"\"This method is not required for eager execution.\"",
"raise",
"AttributeError",
"(",
"error",
")"
] | [
70,
4
] | [
77,
35
] | python | en | ['en', 'error', 'th'] | False |
FastGradientMethod.__init__ | (self, model, dtypestr="float32", **kwargs) |
Creates a FastGradientMethod instance in eager execution.
:model: cleverhans.model.Model
:dtypestr: datatype in the string format.
|
Creates a FastGradientMethod instance in eager execution.
:model: cleverhans.model.Model
:dtypestr: datatype in the string format.
| def __init__(self, model, dtypestr="float32", **kwargs):
"""
Creates a FastGradientMethod instance in eager execution.
:model: cleverhans.model.Model
:dtypestr: datatype in the string format.
"""
del kwargs
if not isinstance(model, Model):
wrapper_warn... | [
"def",
"__init__",
"(",
"self",
",",
"model",
",",
"dtypestr",
"=",
"\"float32\"",
",",
"*",
"*",
"kwargs",
")",
":",
"del",
"kwargs",
"if",
"not",
"isinstance",
"(",
"model",
",",
"Model",
")",
":",
"wrapper_warning",
"(",
")",
"model",
"=",
"Callable... | [
91,
4
] | [
102,
65
] | python | en | ['en', 'error', 'th'] | False |
FastGradientMethod.generate | (self, x, **kwargs) |
Generates the adversarial sample for the given input.
:param x: The model's inputs.
:param eps: (optional float) attack step size (input variation)
:param ord: (optional) Order of the norm (mimics NumPy).
Possible values: np.inf, 1 or 2.
:param y: (optional) ... |
Generates the adversarial sample for the given input.
:param x: The model's inputs.
:param eps: (optional float) attack step size (input variation)
:param ord: (optional) Order of the norm (mimics NumPy).
Possible values: np.inf, 1 or 2.
:param y: (optional) ... | def generate(self, x, **kwargs):
"""
Generates the adversarial sample for the given input.
:param x: The model's inputs.
:param eps: (optional float) attack step size (input variation)
:param ord: (optional) Order of the norm (mimics NumPy).
Possible values: n... | [
"def",
"generate",
"(",
"self",
",",
"x",
",",
"*",
"*",
"kwargs",
")",
":",
"# Parse and save attack-specific parameters",
"assert",
"self",
".",
"parse_params",
"(",
"*",
"*",
"kwargs",
")",
"labels",
",",
"_nb_classes",
"=",
"self",
".",
"get_or_guess_label... | [
104,
4
] | [
126,
79
] | python | en | ['en', 'error', 'th'] | False |
FastGradientMethod.fgm | (self, x, labels, targeted=False) |
TensorFlow Eager implementation of the Fast Gradient Method.
:param x: the input variable
:param targeted: Is the attack targeted or untargeted? Untargeted, the
default, will try to make the label incorrect.
Targeted will instead try to move in ... |
TensorFlow Eager implementation of the Fast Gradient Method.
:param x: the input variable
:param targeted: Is the attack targeted or untargeted? Untargeted, the
default, will try to make the label incorrect.
Targeted will instead try to move in ... | def fgm(self, x, labels, targeted=False):
"""
TensorFlow Eager implementation of the Fast Gradient Method.
:param x: the input variable
:param targeted: Is the attack targeted or untargeted? Untargeted, the
default, will try to make the label incorrect.
... | [
"def",
"fgm",
"(",
"self",
",",
"x",
",",
"labels",
",",
"targeted",
"=",
"False",
")",
":",
"# Compute loss",
"with",
"tf",
".",
"GradientTape",
"(",
")",
"as",
"tape",
":",
"# input should be watched because it may be",
"# combination of trainable and non-trainabl... | [
128,
4
] | [
159,
20
] | python | en | ['en', 'error', 'th'] | False |
BasicIterativeMethod.__init__ | (self, model, dtypestr="float32") |
Creates a BasicIterativeMethod instance in eager execution.
:param model: cleverhans.model.Model
:param dtypestr: datatype in the string format.
|
Creates a BasicIterativeMethod instance in eager execution.
:param model: cleverhans.model.Model
:param dtypestr: datatype in the string format.
| def __init__(self, model, dtypestr="float32"):
"""
Creates a BasicIterativeMethod instance in eager execution.
:param model: cleverhans.model.Model
:param dtypestr: datatype in the string format.
"""
if not isinstance(model, Model):
wrapper_warning()
... | [
"def",
"__init__",
"(",
"self",
",",
"model",
",",
"dtypestr",
"=",
"\"float32\"",
")",
":",
"if",
"not",
"isinstance",
"(",
"model",
",",
"Model",
")",
":",
"wrapper_warning",
"(",
")",
"model",
"=",
"CallableModelWrapper",
"(",
"model",
",",
"\"probs\"",... | [
173,
4
] | [
183,
67
] | python | en | ['en', 'error', 'th'] | False |
i18n_patterns | (prefix, *args) |
Adds the language code prefix to every URL pattern within this
function. This may only be used in the root URLconf, not in an included
URLconf.
|
Adds the language code prefix to every URL pattern within this
function. This may only be used in the root URLconf, not in an included
URLconf.
| def i18n_patterns(prefix, *args):
"""
Adds the language code prefix to every URL pattern within this
function. This may only be used in the root URLconf, not in an included
URLconf.
"""
if isinstance(prefix, six.string_types):
warnings.warn(
"Calling i18n_patterns() with the ... | [
"def",
"i18n_patterns",
"(",
"prefix",
",",
"*",
"args",
")",
":",
"if",
"isinstance",
"(",
"prefix",
",",
"six",
".",
"string_types",
")",
":",
"warnings",
".",
"warn",
"(",
"\"Calling i18n_patterns() with the `prefix` argument and with tuples \"",
"\"instead of djan... | [
10,
0
] | [
29,
49
] | python | en | ['en', 'error', 'th'] | False |
load_images | (input_dir, metadata_file_path, batch_shape) | Retrieve numpy arrays of images and labels, read from a directory. | Retrieve numpy arrays of images and labels, read from a directory. | def load_images(input_dir, metadata_file_path, batch_shape):
"""Retrieve numpy arrays of images and labels, read from a directory."""
num_images = batch_shape[0]
with open(metadata_file_path) as input_file:
reader = csv.reader(input_file)
header_row = next(reader)
rows = list(reader)... | [
"def",
"load_images",
"(",
"input_dir",
",",
"metadata_file_path",
",",
"batch_shape",
")",
":",
"num_images",
"=",
"batch_shape",
"[",
"0",
"]",
"with",
"open",
"(",
"metadata_file_path",
")",
"as",
"input_file",
":",
"reader",
"=",
"csv",
".",
"reader",
"(... | [
72,
0
] | [
92,
25
] | python | en | ['en', 'en', 'en'] | True |
InceptionModel.__call__ | (self, x_input, return_logits=False) | Constructs model and return probabilities for given input. | Constructs model and return probabilities for given input. | def __call__(self, x_input, return_logits=False):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
# Inception preprocessing uses [-1, 1]-scaled input.
x_input = ... | [
"def",
"__call__",
"(",
"self",
",",
"x_input",
",",
"return_logits",
"=",
"False",
")",
":",
"reuse",
"=",
"True",
"if",
"self",
".",
"built",
"else",
"None",
"with",
"slim",
".",
"arg_scope",
"(",
"inception",
".",
"inception_v3_arg_scope",
"(",
")",
"... | [
104,
4
] | [
120,
29
] | python | en | ['en', 'en', 'en'] | True |
TestInception.test_clean_accuracy | (self) | Check model is accurate on unperturbed images. | Check model is accurate on unperturbed images. | def test_clean_accuracy(self):
"""Check model is accurate on unperturbed images."""
input_dir = FLAGS.input_image_dir
metadata_file_path = FLAGS.metadata_file_path
num_images = 16
batch_shape = (num_images, 299, 299, 3)
images, labels = load_images(input_dir, metadata_fil... | [
"def",
"test_clean_accuracy",
"(",
"self",
")",
":",
"input_dir",
"=",
"FLAGS",
".",
"input_image_dir",
"metadata_file_path",
"=",
"FLAGS",
".",
"metadata_file_path",
"num_images",
"=",
"16",
"batch_shape",
"=",
"(",
"num_images",
",",
"299",
",",
"299",
",",
... | [
134,
4
] | [
164,
36
] | python | en | ['en', 'en', 'en'] | True |
TestSPSA.test_attack_bounds | (self) | Check SPSA respects perturbation limits. | Check SPSA respects perturbation limits. | def test_attack_bounds(self):
"""Check SPSA respects perturbation limits."""
epsilon = 4.0 / 255
input_dir = FLAGS.input_image_dir
metadata_file_path = FLAGS.metadata_file_path
num_images = 8
batch_shape = (num_images, 299, 299, 3)
images, labels = load_images(inp... | [
"def",
"test_attack_bounds",
"(",
"self",
")",
":",
"epsilon",
"=",
"4.0",
"/",
"255",
"input_dir",
"=",
"FLAGS",
".",
"input_image_dir",
"metadata_file_path",
"=",
"FLAGS",
".",
"metadata_file_path",
"num_images",
"=",
"8",
"batch_shape",
"=",
"(",
"num_images"... | [
168,
4
] | [
216,
52
] | python | en | ['en', 'bg-Latn', 'en'] | True |
TestSPSA.test_attack_success | (self) | Check SPSA creates misclassified images. | Check SPSA creates misclassified images. | def test_attack_success(self):
"""Check SPSA creates misclassified images."""
epsilon = 4.0 / 255
input_dir = FLAGS.input_image_dir
metadata_file_path = FLAGS.metadata_file_path
num_images = 8
batch_shape = (num_images, 299, 299, 3)
images, labels = load_images(in... | [
"def",
"test_attack_success",
"(",
"self",
")",
":",
"epsilon",
"=",
"4.0",
"/",
"255",
"input_dir",
"=",
"FLAGS",
".",
"input_image_dir",
"metadata_file_path",
"=",
"FLAGS",
".",
"metadata_file_path",
"num_images",
"=",
"8",
"batch_shape",
"=",
"(",
"num_images... | [
218,
4
] | [
268,
55
] | python | en | ['en', 'en', 'en'] | True |
_pickle_queryset | (class_bases, class_dict) |
Used by `__reduce__` to create the initial version of the `QuerySet` class
onto which the output of `__getstate__` will be applied.
See `__reduce__` for more details.
|
Used by `__reduce__` to create the initial version of the `QuerySet` class
onto which the output of `__getstate__` will be applied. | def _pickle_queryset(class_bases, class_dict):
"""
Used by `__reduce__` to create the initial version of the `QuerySet` class
onto which the output of `__getstate__` will be applied.
See `__reduce__` for more details.
"""
new = Empty()
new.__class__ = type(class_bases[0].__name__, class_bas... | [
"def",
"_pickle_queryset",
"(",
"class_bases",
",",
"class_dict",
")",
":",
"new",
"=",
"Empty",
"(",
")",
"new",
".",
"__class__",
"=",
"type",
"(",
"class_bases",
"[",
"0",
"]",
".",
"__name__",
",",
"class_bases",
",",
"class_dict",
")",
"return",
"ne... | [
36,
0
] | [
45,
14
] | python | en | ['en', 'error', 'th'] | False |
get_klass_info | (klass, max_depth=0, cur_depth=0, requested=None,
only_load=None, from_parent=None) |
Helper function that recursively returns an information for a klass, to be
used in get_cached_row. It exists just to compute this information only
once for entire queryset. Otherwise it would be computed for each row, which
leads to poor performance on large querysets.
Arguments:
* klass - t... |
Helper function that recursively returns an information for a klass, to be
used in get_cached_row. It exists just to compute this information only
once for entire queryset. Otherwise it would be computed for each row, which
leads to poor performance on large querysets. | def get_klass_info(klass, max_depth=0, cur_depth=0, requested=None,
only_load=None, from_parent=None):
"""
Helper function that recursively returns an information for a klass, to be
used in get_cached_row. It exists just to compute this information only
once for entire queryset. Othe... | [
"def",
"get_klass_info",
"(",
"klass",
",",
"max_depth",
"=",
"0",
",",
"cur_depth",
"=",
"0",
",",
"requested",
"=",
"None",
",",
"only_load",
"=",
"None",
",",
"from_parent",
"=",
"None",
")",
":",
"if",
"max_depth",
"and",
"requested",
"is",
"None",
... | [
1295,
0
] | [
1407,
90
] | python | en | ['en', 'error', 'th'] | False |
reorder_for_init | (model, field_names, values) |
Reorders given field names and values for those fields
to be in the same order as model.__init__() expects to find them.
|
Reorders given field names and values for those fields
to be in the same order as model.__init__() expects to find them.
| def reorder_for_init(model, field_names, values):
"""
Reorders given field names and values for those fields
to be in the same order as model.__init__() expects to find them.
"""
new_names, new_values = [], []
for f in model._meta.concrete_fields:
if f.attname not in field_names:
... | [
"def",
"reorder_for_init",
"(",
"model",
",",
"field_names",
",",
"values",
")",
":",
"new_names",
",",
"new_values",
"=",
"[",
"]",
",",
"[",
"]",
"for",
"f",
"in",
"model",
".",
"_meta",
".",
"concrete_fields",
":",
"if",
"f",
".",
"attname",
"not",
... | [
1410,
0
] | [
1422,
32
] | python | en | ['en', 'error', 'th'] | False |
get_cached_row | (row, index_start, using, klass_info, offset=0,
parent_data=()) |
Helper function that recursively returns an object with the specified
related attributes already populated.
This method may be called recursively to populate deep select_related()
clauses.
Arguments:
* row - the row of data returned by the database cursor
* index_start - the ind... |
Helper function that recursively returns an object with the specified
related attributes already populated. | def get_cached_row(row, index_start, using, klass_info, offset=0,
parent_data=()):
"""
Helper function that recursively returns an object with the specified
related attributes already populated.
This method may be called recursively to populate deep select_related()
clauses.
... | [
"def",
"get_cached_row",
"(",
"row",
",",
"index_start",
",",
"using",
",",
"klass_info",
",",
"offset",
"=",
"0",
",",
"parent_data",
"=",
"(",
")",
")",
":",
"if",
"klass_info",
"is",
"None",
":",
"return",
"None",
"klass",
",",
"field_names",
",",
"... | [
1425,
0
] | [
1525,
25
] | python | en | ['en', 'error', 'th'] | False |
normalize_prefetch_lookups | (lookups, prefix=None) |
Helper function that normalize lookups into Prefetch objects.
|
Helper function that normalize lookups into Prefetch objects.
| def normalize_prefetch_lookups(lookups, prefix=None):
"""
Helper function that normalize lookups into Prefetch objects.
"""
ret = []
for lookup in lookups:
if not isinstance(lookup, Prefetch):
lookup = Prefetch(lookup)
if prefix:
lookup.add_prefix(prefix)
... | [
"def",
"normalize_prefetch_lookups",
"(",
"lookups",
",",
"prefix",
"=",
"None",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"lookup",
"in",
"lookups",
":",
"if",
"not",
"isinstance",
"(",
"lookup",
",",
"Prefetch",
")",
":",
"lookup",
"=",
"Prefetch",
"(",
... | [
1690,
0
] | [
1701,
14
] | python | en | ['en', 'error', 'th'] | False |
prefetch_related_objects | (result_cache, related_lookups) |
Helper function for prefetch_related functionality
Populates prefetched objects caches for a list of results
from a QuerySet
|
Helper function for prefetch_related functionality | def prefetch_related_objects(result_cache, related_lookups):
"""
Helper function for prefetch_related functionality
Populates prefetched objects caches for a list of results
from a QuerySet
"""
if len(result_cache) == 0:
return # nothing to do
related_lookups = normalize_prefetch... | [
"def",
"prefetch_related_objects",
"(",
"result_cache",
",",
"related_lookups",
")",
":",
"if",
"len",
"(",
"result_cache",
")",
"==",
"0",
":",
"return",
"# nothing to do",
"related_lookups",
"=",
"normalize_prefetch_lookups",
"(",
"related_lookups",
")",
"# We need ... | [
1704,
0
] | [
1825,
39
] | python | en | ['en', 'error', 'th'] | False |
get_prefetcher | (instance, attr) |
For the attribute 'attr' on the given instance, finds
an object that has a get_prefetch_queryset().
Returns a 4 tuple containing:
(the object with get_prefetch_queryset (or None),
the descriptor object representing this relationship (or None),
a boolean that is False if the attribute was not ... |
For the attribute 'attr' on the given instance, finds
an object that has a get_prefetch_queryset().
Returns a 4 tuple containing:
(the object with get_prefetch_queryset (or None),
the descriptor object representing this relationship (or None),
a boolean that is False if the attribute was not ... | def get_prefetcher(instance, attr):
"""
For the attribute 'attr' on the given instance, finds
an object that has a get_prefetch_queryset().
Returns a 4 tuple containing:
(the object with get_prefetch_queryset (or None),
the descriptor object representing this relationship (or None),
a bool... | [
"def",
"get_prefetcher",
"(",
"instance",
",",
"attr",
")",
":",
"prefetcher",
"=",
"None",
"is_fetched",
"=",
"False",
"# For singly related objects, we have to avoid getting the attribute",
"# from the object, as this will trigger the query. So we first try",
"# on the class, in or... | [
1828,
0
] | [
1863,
65
] | python | en | ['en', 'error', 'th'] | False |
prefetch_one_level | (instances, prefetcher, lookup, level) |
Helper function for prefetch_related_objects
Runs prefetches on all instances using the prefetcher object,
assigning results to relevant caches in instance.
The prefetched objects are returned, along with any additional
prefetches that must be done due to prefetch_related lookups
found from d... |
Helper function for prefetch_related_objects | def prefetch_one_level(instances, prefetcher, lookup, level):
"""
Helper function for prefetch_related_objects
Runs prefetches on all instances using the prefetcher object,
assigning results to relevant caches in instance.
The prefetched objects are returned, along with any additional
prefetch... | [
"def",
"prefetch_one_level",
"(",
"instances",
",",
"prefetcher",
",",
"lookup",
",",
"level",
")",
":",
"# prefetcher must have a method get_prefetch_queryset() which takes a list",
"# of instances, and returns a tuple:",
"# (queryset of instances of self.model that are related to passe... | [
1866,
0
] | [
1928,
50
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.__deepcopy__ | (self, memo) |
Deep copy of a QuerySet doesn't populate the cache
|
Deep copy of a QuerySet doesn't populate the cache
| def __deepcopy__(self, memo):
"""
Deep copy of a QuerySet doesn't populate the cache
"""
obj = self.__class__()
for k, v in self.__dict__.items():
if k == '_result_cache':
obj.__dict__[k] = None
else:
obj.__dict__[k] = copy.... | [
"def",
"__deepcopy__",
"(",
"self",
",",
"memo",
")",
":",
"obj",
"=",
"self",
".",
"__class__",
"(",
")",
"for",
"k",
",",
"v",
"in",
"self",
".",
"__dict__",
".",
"items",
"(",
")",
":",
"if",
"k",
"==",
"'_result_cache'",
":",
"obj",
".",
"__d... | [
76,
4
] | [
86,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.__getstate__ | (self) |
Allows the QuerySet to be pickled.
|
Allows the QuerySet to be pickled.
| def __getstate__(self):
"""
Allows the QuerySet to be pickled.
"""
# Force the cache to be fully populated.
self._fetch_all()
obj_dict = self.__dict__.copy()
obj_dict[DJANGO_VERSION_PICKLE_KEY] = get_version()
return obj_dict | [
"def",
"__getstate__",
"(",
"self",
")",
":",
"# Force the cache to be fully populated.",
"self",
".",
"_fetch_all",
"(",
")",
"obj_dict",
"=",
"self",
".",
"__dict__",
".",
"copy",
"(",
")",
"obj_dict",
"[",
"DJANGO_VERSION_PICKLE_KEY",
"]",
"=",
"get_version",
... | [
88,
4
] | [
96,
23
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.__reduce__ | (self) |
Used by pickle to deal with the types that we create dynamically when
specialized queryset such as `ValuesQuerySet` are used in conjunction
with querysets that are *subclasses* of `QuerySet`.
See `_clone` implementation for more details.
|
Used by pickle to deal with the types that we create dynamically when
specialized queryset such as `ValuesQuerySet` are used in conjunction
with querysets that are *subclasses* of `QuerySet`. | def __reduce__(self):
"""
Used by pickle to deal with the types that we create dynamically when
specialized queryset such as `ValuesQuerySet` are used in conjunction
with querysets that are *subclasses* of `QuerySet`.
See `_clone` implementation for more details.
"""
... | [
"def",
"__reduce__",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_specialized_queryset_class'",
")",
":",
"class_bases",
"=",
"(",
"self",
".",
"_specialized_queryset_class",
",",
"self",
".",
"_base_queryset_class",
",",
")",
"class_dict",
"=",
... | [
115,
4
] | [
133,
49
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.__iter__ | (self) |
The queryset iterator protocol uses three nested iterators in the
default case:
1. sql.compiler:execute_sql()
- Returns 100 rows at time (constants.GET_ITERATOR_CHUNK_SIZE)
using cursor.fetchmany(). This part is responsible for
doing some col... |
The queryset iterator protocol uses three nested iterators in the
default case:
1. sql.compiler:execute_sql()
- Returns 100 rows at time (constants.GET_ITERATOR_CHUNK_SIZE)
using cursor.fetchmany(). This part is responsible for
doing some col... | def __iter__(self):
"""
The queryset iterator protocol uses three nested iterators in the
default case:
1. sql.compiler:execute_sql()
- Returns 100 rows at time (constants.GET_ITERATOR_CHUNK_SIZE)
using cursor.fetchmany(). This part is responsible for
... | [
"def",
"__iter__",
"(",
"self",
")",
":",
"self",
".",
"_fetch_all",
"(",
")",
"return",
"iter",
"(",
"self",
".",
"_result_cache",
")"
] | [
145,
4
] | [
162,
39
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.__getitem__ | (self, k) |
Retrieves an item or slice from the set of results.
|
Retrieves an item or slice from the set of results.
| def __getitem__(self, k):
"""
Retrieves an item or slice from the set of results.
"""
if not isinstance(k, (slice,) + six.integer_types):
raise TypeError
assert ((not isinstance(k, slice) and (k >= 0)) or
(isinstance(k, slice) and (k.start is None or k... | [
"def",
"__getitem__",
"(",
"self",
",",
"k",
")",
":",
"if",
"not",
"isinstance",
"(",
"k",
",",
"(",
"slice",
",",
")",
"+",
"six",
".",
"integer_types",
")",
":",
"raise",
"TypeError",
"assert",
"(",
"(",
"not",
"isinstance",
"(",
"k",
",",
"slic... | [
168,
4
] | [
197,
26
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.iterator | (self) |
An iterator over the results from applying this QuerySet to the
database.
|
An iterator over the results from applying this QuerySet to the
database.
| def iterator(self):
"""
An iterator over the results from applying this QuerySet to the
database.
"""
fill_cache = False
if connections[self.db].features.supports_select_related:
fill_cache = self.query.select_related
if isinstance(fill_cache, dict):
... | [
"def",
"iterator",
"(",
"self",
")",
":",
"fill_cache",
"=",
"False",
"if",
"connections",
"[",
"self",
".",
"db",
"]",
".",
"features",
".",
"supports_select_related",
":",
"fill_cache",
"=",
"self",
".",
"query",
".",
"select_related",
"if",
"isinstance",
... | [
225,
4
] | [
316,
21
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.aggregate | (self, *args, **kwargs) |
Returns a dictionary containing the calculations (aggregation)
over the current queryset
If args is present the expression is passed as a kwarg using
the Aggregate object's default alias.
|
Returns a dictionary containing the calculations (aggregation)
over the current queryset | def aggregate(self, *args, **kwargs):
"""
Returns a dictionary containing the calculations (aggregation)
over the current queryset
If args is present the expression is passed as a kwarg using
the Aggregate object's default alias.
"""
if self.query.distinct_fields... | [
"def",
"aggregate",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"query",
".",
"distinct_fields",
":",
"raise",
"NotImplementedError",
"(",
"\"aggregate() + distinct(fields) not implemented.\"",
")",
"for",
"arg",
"in",
... | [
318,
4
] | [
336,
74
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.count | (self) |
Performs a SELECT COUNT() and returns the number of records as an
integer.
If the QuerySet is already fully cached this simply returns the length
of the cached results set to avoid multiple SELECT COUNT(*) calls.
|
Performs a SELECT COUNT() and returns the number of records as an
integer. | def count(self):
"""
Performs a SELECT COUNT() and returns the number of records as an
integer.
If the QuerySet is already fully cached this simply returns the length
of the cached results set to avoid multiple SELECT COUNT(*) calls.
"""
if self._result_cache is ... | [
"def",
"count",
"(",
"self",
")",
":",
"if",
"self",
".",
"_result_cache",
"is",
"not",
"None",
":",
"return",
"len",
"(",
"self",
".",
"_result_cache",
")",
"return",
"self",
".",
"query",
".",
"get_count",
"(",
"using",
"=",
"self",
".",
"db",
")"
... | [
338,
4
] | [
349,
50
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.get | (self, *args, **kwargs) |
Performs the query and returns a single object matching the given
keyword arguments.
|
Performs the query and returns a single object matching the given
keyword arguments.
| def get(self, *args, **kwargs):
"""
Performs the query and returns a single object matching the given
keyword arguments.
"""
clone = self.filter(*args, **kwargs)
if self.query.can_filter():
clone = clone.order_by()
if (not clone.query.select_for_update... | [
"def",
"get",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"clone",
"=",
"self",
".",
"filter",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
":",
"clone",
"=",
"... | [
351,
4
] | [
374,
9
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.create | (self, **kwargs) |
Creates a new object with the given kwargs, saving it to the database
and returning the created object.
|
Creates a new object with the given kwargs, saving it to the database
and returning the created object.
| def create(self, **kwargs):
"""
Creates a new object with the given kwargs, saving it to the database
and returning the created object.
"""
obj = self.model(**kwargs)
self._for_write = True
obj.save(force_insert=True, using=self.db)
return obj | [
"def",
"create",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"obj",
"=",
"self",
".",
"model",
"(",
"*",
"*",
"kwargs",
")",
"self",
".",
"_for_write",
"=",
"True",
"obj",
".",
"save",
"(",
"force_insert",
"=",
"True",
",",
"using",
"=",
"sel... | [
376,
4
] | [
384,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.bulk_create | (self, objs, batch_size=None) |
Inserts each of the instances into the database. This does *not* call
save() on each of the instances, does not send any pre/post save
signals, and does not set the primary key attribute if it is an
autoincrement field.
|
Inserts each of the instances into the database. This does *not* call
save() on each of the instances, does not send any pre/post save
signals, and does not set the primary key attribute if it is an
autoincrement field.
| def bulk_create(self, objs, batch_size=None):
"""
Inserts each of the instances into the database. This does *not* call
save() on each of the instances, does not send any pre/post save
signals, and does not set the primary key attribute if it is an
autoincrement field.
""... | [
"def",
"bulk_create",
"(",
"self",
",",
"objs",
",",
"batch_size",
"=",
"None",
")",
":",
"# So this case is fun. When you bulk insert you don't get the primary",
"# keys back (if it's an autoincrement), so you can't insert into the",
"# child tables which references this. There are two ... | [
386,
4
] | [
422,
19
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.get_or_create | (self, defaults=None, **kwargs) |
Looks up an object with the given kwargs, creating one if necessary.
Returns a tuple of (object, created), where created is a boolean
specifying whether an object was created.
|
Looks up an object with the given kwargs, creating one if necessary.
Returns a tuple of (object, created), where created is a boolean
specifying whether an object was created.
| def get_or_create(self, defaults=None, **kwargs):
"""
Looks up an object with the given kwargs, creating one if necessary.
Returns a tuple of (object, created), where created is a boolean
specifying whether an object was created.
"""
lookup, params = self._extract_model_p... | [
"def",
"get_or_create",
"(",
"self",
",",
"defaults",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"lookup",
",",
"params",
"=",
"self",
".",
"_extract_model_params",
"(",
"defaults",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"_for_write",
"=",
"Tr... | [
424,
4
] | [
435,
66
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.update_or_create | (self, defaults=None, **kwargs) |
Looks up an object with the given kwargs, updating one with defaults
if it exists, otherwise creates a new one.
Returns a tuple (object, created), where created is a boolean
specifying whether an object was created.
|
Looks up an object with the given kwargs, updating one with defaults
if it exists, otherwise creates a new one.
Returns a tuple (object, created), where created is a boolean
specifying whether an object was created.
| def update_or_create(self, defaults=None, **kwargs):
"""
Looks up an object with the given kwargs, updating one with defaults
if it exists, otherwise creates a new one.
Returns a tuple (object, created), where created is a boolean
specifying whether an object was created.
... | [
"def",
"update_or_create",
"(",
"self",
",",
"defaults",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"defaults",
"=",
"defaults",
"or",
"{",
"}",
"lookup",
",",
"params",
"=",
"self",
".",
"_extract_model_params",
"(",
"defaults",
",",
"*",
"*",
"k... | [
437,
4
] | [
458,
25
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._create_object_from_params | (self, lookup, params) |
Tries to create an object using passed params.
Used by get_or_create and update_or_create
|
Tries to create an object using passed params.
Used by get_or_create and update_or_create
| def _create_object_from_params(self, lookup, params):
"""
Tries to create an object using passed params.
Used by get_or_create and update_or_create
"""
try:
with transaction.atomic(using=self.db):
obj = self.create(**params)
return obj, Tru... | [
"def",
"_create_object_from_params",
"(",
"self",
",",
"lookup",
",",
"params",
")",
":",
"try",
":",
"with",
"transaction",
".",
"atomic",
"(",
"using",
"=",
"self",
".",
"db",
")",
":",
"obj",
"=",
"self",
".",
"create",
"(",
"*",
"*",
"params",
")... | [
460,
4
] | [
475,
34
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._extract_model_params | (self, defaults, **kwargs) |
Prepares `lookup` (kwargs that are valid model attributes), `params`
(for creating a model instance) based on given kwargs; for use by
get_or_create and update_or_create.
|
Prepares `lookup` (kwargs that are valid model attributes), `params`
(for creating a model instance) based on given kwargs; for use by
get_or_create and update_or_create.
| def _extract_model_params(self, defaults, **kwargs):
"""
Prepares `lookup` (kwargs that are valid model attributes), `params`
(for creating a model instance) based on given kwargs; for use by
get_or_create and update_or_create.
"""
defaults = defaults or {}
lookup... | [
"def",
"_extract_model_params",
"(",
"self",
",",
"defaults",
",",
"*",
"*",
"kwargs",
")",
":",
"defaults",
"=",
"defaults",
"or",
"{",
"}",
"lookup",
"=",
"kwargs",
".",
"copy",
"(",
")",
"for",
"f",
"in",
"self",
".",
"model",
".",
"_meta",
".",
... | [
477,
4
] | [
490,
29
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._earliest_or_latest | (self, field_name=None, direction="-") |
Returns the latest object, according to the model's
'get_latest_by' option or optional given field_name.
|
Returns the latest object, according to the model's
'get_latest_by' option or optional given field_name.
| def _earliest_or_latest(self, field_name=None, direction="-"):
"""
Returns the latest object, according to the model's
'get_latest_by' option or optional given field_name.
"""
order_by = field_name or getattr(self.model._meta, 'get_latest_by')
assert bool(order_by), "earl... | [
"def",
"_earliest_or_latest",
"(",
"self",
",",
"field_name",
"=",
"None",
",",
"direction",
"=",
"\"-\"",
")",
":",
"order_by",
"=",
"field_name",
"or",
"getattr",
"(",
"self",
".",
"model",
".",
"_meta",
",",
"'get_latest_by'",
")",
"assert",
"bool",
"("... | [
492,
4
] | [
506,
24
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.first | (self) |
Returns the first object of a query, returns None if no match is found.
|
Returns the first object of a query, returns None if no match is found.
| def first(self):
"""
Returns the first object of a query, returns None if no match is found.
"""
objects = list((self if self.ordered else self.order_by('pk'))[:1])
if objects:
return objects[0]
return None | [
"def",
"first",
"(",
"self",
")",
":",
"objects",
"=",
"list",
"(",
"(",
"self",
"if",
"self",
".",
"ordered",
"else",
"self",
".",
"order_by",
"(",
"'pk'",
")",
")",
"[",
":",
"1",
"]",
")",
"if",
"objects",
":",
"return",
"objects",
"[",
"0",
... | [
514,
4
] | [
521,
19
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.last | (self) |
Returns the last object of a query, returns None if no match is found.
|
Returns the last object of a query, returns None if no match is found.
| def last(self):
"""
Returns the last object of a query, returns None if no match is found.
"""
objects = list((self.reverse() if self.ordered else self.order_by('-pk'))[:1])
if objects:
return objects[0]
return None | [
"def",
"last",
"(",
"self",
")",
":",
"objects",
"=",
"list",
"(",
"(",
"self",
".",
"reverse",
"(",
")",
"if",
"self",
".",
"ordered",
"else",
"self",
".",
"order_by",
"(",
"'-pk'",
")",
")",
"[",
":",
"1",
"]",
")",
"if",
"objects",
":",
"ret... | [
523,
4
] | [
530,
19
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.in_bulk | (self, id_list) |
Returns a dictionary mapping each of the given IDs to the object with
that ID.
|
Returns a dictionary mapping each of the given IDs to the object with
that ID.
| def in_bulk(self, id_list):
"""
Returns a dictionary mapping each of the given IDs to the object with
that ID.
"""
assert self.query.can_filter(), \
"Cannot use 'limit' or 'offset' with in_bulk"
if not id_list:
return {}
qs = self.filter(pk... | [
"def",
"in_bulk",
"(",
"self",
",",
"id_list",
")",
":",
"assert",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
",",
"\"Cannot use 'limit' or 'offset' with in_bulk\"",
"if",
"not",
"id_list",
":",
"return",
"{",
"}",
"qs",
"=",
"self",
".",
"filter",
... | [
532,
4
] | [
542,
59
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.delete | (self) |
Deletes the records in the current QuerySet.
|
Deletes the records in the current QuerySet.
| def delete(self):
"""
Deletes the records in the current QuerySet.
"""
assert self.query.can_filter(), \
"Cannot use 'limit' or 'offset' with delete."
del_query = self._clone()
# The delete is actually 2 queries - one to find related objects,
# and o... | [
"def",
"delete",
"(",
"self",
")",
":",
"assert",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
",",
"\"Cannot use 'limit' or 'offset' with delete.\"",
"del_query",
"=",
"self",
".",
"_clone",
"(",
")",
"# The delete is actually 2 queries - one to find related obje... | [
544,
4
] | [
568,
33
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._raw_delete | (self, using) |
Deletes objects found from the given queryset in single direct SQL
query. No signals are sent, and there is no protection for cascades.
|
Deletes objects found from the given queryset in single direct SQL
query. No signals are sent, and there is no protection for cascades.
| def _raw_delete(self, using):
"""
Deletes objects found from the given queryset in single direct SQL
query. No signals are sent, and there is no protection for cascades.
"""
sql.DeleteQuery(self.model).delete_qs(self, using) | [
"def",
"_raw_delete",
"(",
"self",
",",
"using",
")",
":",
"sql",
".",
"DeleteQuery",
"(",
"self",
".",
"model",
")",
".",
"delete_qs",
"(",
"self",
",",
"using",
")"
] | [
572,
4
] | [
577,
58
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.update | (self, **kwargs) |
Updates all elements in the current QuerySet, setting all the given
fields to the appropriate values.
|
Updates all elements in the current QuerySet, setting all the given
fields to the appropriate values.
| def update(self, **kwargs):
"""
Updates all elements in the current QuerySet, setting all the given
fields to the appropriate values.
"""
assert self.query.can_filter(), \
"Cannot update a query once a slice has been taken."
self._for_write = True
quer... | [
"def",
"update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"assert",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
",",
"\"Cannot update a query once a slice has been taken.\"",
"self",
".",
"_for_write",
"=",
"True",
"query",
"=",
"self",
".",
"q... | [
580,
4
] | [
593,
19
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._update | (self, values) |
A version of update that accepts field objects instead of field names.
Used primarily for model saving and not intended for use by general
code (it requires too much poking around at model internals to be
useful at that level).
|
A version of update that accepts field objects instead of field names.
Used primarily for model saving and not intended for use by general
code (it requires too much poking around at model internals to be
useful at that level).
| def _update(self, values):
"""
A version of update that accepts field objects instead of field names.
Used primarily for model saving and not intended for use by general
code (it requires too much poking around at model internals to be
useful at that level).
"""
a... | [
"def",
"_update",
"(",
"self",
",",
"values",
")",
":",
"assert",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
",",
"\"Cannot update a query once a slice has been taken.\"",
"query",
"=",
"self",
".",
"query",
".",
"clone",
"(",
"sql",
".",
"UpdateQuery"... | [
596,
4
] | [
608,
62
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.dates | (self, field_name, kind, order='ASC') |
Returns a list of date objects representing all available dates for
the given field_name, scoped to 'kind'.
|
Returns a list of date objects representing all available dates for
the given field_name, scoped to 'kind'.
| def dates(self, field_name, kind, order='ASC'):
"""
Returns a list of date objects representing all available dates for
the given field_name, scoped to 'kind'.
"""
assert kind in ("year", "month", "day"), \
"'kind' must be one of 'year', 'month' or 'day'."
ass... | [
"def",
"dates",
"(",
"self",
",",
"field_name",
",",
"kind",
",",
"order",
"=",
"'ASC'",
")",
":",
"assert",
"kind",
"in",
"(",
"\"year\"",
",",
"\"month\"",
",",
"\"day\"",
")",
",",
"\"'kind' must be one of 'year', 'month' or 'day'.\"",
"assert",
"order",
"i... | [
646,
4
] | [
656,
62
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.datetimes | (self, field_name, kind, order='ASC', tzinfo=None) |
Returns a list of datetime objects representing all available
datetimes for the given field_name, scoped to 'kind'.
|
Returns a list of datetime objects representing all available
datetimes for the given field_name, scoped to 'kind'.
| def datetimes(self, field_name, kind, order='ASC', tzinfo=None):
"""
Returns a list of datetime objects representing all available
datetimes for the given field_name, scoped to 'kind'.
"""
assert kind in ("year", "month", "day", "hour", "minute", "second"), \
"'kind' ... | [
"def",
"datetimes",
"(",
"self",
",",
"field_name",
",",
"kind",
",",
"order",
"=",
"'ASC'",
",",
"tzinfo",
"=",
"None",
")",
":",
"assert",
"kind",
"in",
"(",
"\"year\"",
",",
"\"month\"",
",",
"\"day\"",
",",
"\"hour\"",
",",
"\"minute\"",
",",
"\"se... | [
658,
4
] | [
673,
81
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.none | (self) |
Returns an empty QuerySet.
|
Returns an empty QuerySet.
| def none(self):
"""
Returns an empty QuerySet.
"""
clone = self._clone()
clone.query.set_empty()
return clone | [
"def",
"none",
"(",
"self",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"clone",
".",
"query",
".",
"set_empty",
"(",
")",
"return",
"clone"
] | [
675,
4
] | [
681,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.all | (self) |
Returns a new QuerySet that is a copy of the current one. This allows a
QuerySet to proxy for a model manager in some cases.
|
Returns a new QuerySet that is a copy of the current one. This allows a
QuerySet to proxy for a model manager in some cases.
| def all(self):
"""
Returns a new QuerySet that is a copy of the current one. This allows a
QuerySet to proxy for a model manager in some cases.
"""
return self._clone() | [
"def",
"all",
"(",
"self",
")",
":",
"return",
"self",
".",
"_clone",
"(",
")"
] | [
687,
4
] | [
692,
28
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.filter | (self, *args, **kwargs) |
Returns a new QuerySet instance with the args ANDed to the existing
set.
|
Returns a new QuerySet instance with the args ANDed to the existing
set.
| def filter(self, *args, **kwargs):
"""
Returns a new QuerySet instance with the args ANDed to the existing
set.
"""
return self._filter_or_exclude(False, *args, **kwargs) | [
"def",
"filter",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_filter_or_exclude",
"(",
"False",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
694,
4
] | [
699,
62
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.exclude | (self, *args, **kwargs) |
Returns a new QuerySet instance with NOT (args) ANDed to the existing
set.
|
Returns a new QuerySet instance with NOT (args) ANDed to the existing
set.
| def exclude(self, *args, **kwargs):
"""
Returns a new QuerySet instance with NOT (args) ANDed to the existing
set.
"""
return self._filter_or_exclude(True, *args, **kwargs) | [
"def",
"exclude",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_filter_or_exclude",
"(",
"True",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
701,
4
] | [
706,
61
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.complex_filter | (self, filter_obj) |
Returns a new QuerySet instance with filter_obj added to the filters.
filter_obj can be a Q object (or anything with an add_to_query()
method) or a dictionary of keyword lookup arguments.
This exists to support framework features such as 'limit_choices_to',
and usually it will... |
Returns a new QuerySet instance with filter_obj added to the filters. | def complex_filter(self, filter_obj):
"""
Returns a new QuerySet instance with filter_obj added to the filters.
filter_obj can be a Q object (or anything with an add_to_query()
method) or a dictionary of keyword lookup arguments.
This exists to support framework features such a... | [
"def",
"complex_filter",
"(",
"self",
",",
"filter_obj",
")",
":",
"if",
"isinstance",
"(",
"filter_obj",
",",
"Q",
")",
"or",
"hasattr",
"(",
"filter_obj",
",",
"'add_to_query'",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"clone",
".",
"... | [
720,
4
] | [
735,
62
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.select_for_update | (self, nowait=False) |
Returns a new QuerySet instance that will select objects with a
FOR UPDATE lock.
|
Returns a new QuerySet instance that will select objects with a
FOR UPDATE lock.
| def select_for_update(self, nowait=False):
"""
Returns a new QuerySet instance that will select objects with a
FOR UPDATE lock.
"""
obj = self._clone()
obj._for_write = True
obj.query.select_for_update = True
obj.query.select_for_update_nowait = nowait
... | [
"def",
"select_for_update",
"(",
"self",
",",
"nowait",
"=",
"False",
")",
":",
"obj",
"=",
"self",
".",
"_clone",
"(",
")",
"obj",
".",
"_for_write",
"=",
"True",
"obj",
".",
"query",
".",
"select_for_update",
"=",
"True",
"obj",
".",
"query",
".",
... | [
737,
4
] | [
746,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.select_related | (self, *fields) |
Returns a new QuerySet instance that will select related objects.
If fields are specified, they must be ForeignKey fields and only those
related objects are included in the selection.
If select_related(None) is called, the list is cleared.
|
Returns a new QuerySet instance that will select related objects. | def select_related(self, *fields):
"""
Returns a new QuerySet instance that will select related objects.
If fields are specified, they must be ForeignKey fields and only those
related objects are included in the selection.
If select_related(None) is called, the list is cleared.... | [
"def",
"select_related",
"(",
"self",
",",
"*",
"fields",
")",
":",
"obj",
"=",
"self",
".",
"_clone",
"(",
")",
"if",
"fields",
"==",
"(",
"None",
",",
")",
":",
"obj",
".",
"query",
".",
"select_related",
"=",
"False",
"elif",
"fields",
":",
"obj... | [
748,
4
] | [
764,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.prefetch_related | (self, *lookups) |
Returns a new QuerySet instance that will prefetch the specified
Many-To-One and Many-To-Many related objects when the QuerySet is
evaluated.
When prefetch_related() is called more than once, the list of lookups to
prefetch is appended to. If prefetch_related(None) is called, t... |
Returns a new QuerySet instance that will prefetch the specified
Many-To-One and Many-To-Many related objects when the QuerySet is
evaluated. | def prefetch_related(self, *lookups):
"""
Returns a new QuerySet instance that will prefetch the specified
Many-To-One and Many-To-Many related objects when the QuerySet is
evaluated.
When prefetch_related() is called more than once, the list of lookups to
prefetch is ap... | [
"def",
"prefetch_related",
"(",
"self",
",",
"*",
"lookups",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"if",
"lookups",
"==",
"(",
"None",
",",
")",
":",
"clone",
".",
"_prefetch_related_lookups",
"=",
"[",
"]",
"else",
":",
"clone",
"... | [
766,
4
] | [
781,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.annotate | (self, *args, **kwargs) |
Return a query set in which the returned objects have been annotated
with data aggregated from related fields.
|
Return a query set in which the returned objects have been annotated
with data aggregated from related fields.
| def annotate(self, *args, **kwargs):
"""
Return a query set in which the returned objects have been annotated
with data aggregated from related fields.
"""
for arg in args:
if arg.default_alias in kwargs:
raise ValueError("The named annotation '%s' con... | [
"def",
"annotate",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"arg",
"in",
"args",
":",
"if",
"arg",
".",
"default_alias",
"in",
"kwargs",
":",
"raise",
"ValueError",
"(",
"\"The named annotation '%s' conflicts with the \"",
"\"... | [
783,
4
] | [
812,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.order_by | (self, *field_names) |
Returns a new QuerySet instance with the ordering changed.
|
Returns a new QuerySet instance with the ordering changed.
| def order_by(self, *field_names):
"""
Returns a new QuerySet instance with the ordering changed.
"""
assert self.query.can_filter(), \
"Cannot reorder a query once a slice has been taken."
obj = self._clone()
obj.query.clear_ordering(force_empty=False)
... | [
"def",
"order_by",
"(",
"self",
",",
"*",
"field_names",
")",
":",
"assert",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
",",
"\"Cannot reorder a query once a slice has been taken.\"",
"obj",
"=",
"self",
".",
"_clone",
"(",
")",
"obj",
".",
"query",
... | [
814,
4
] | [
823,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.distinct | (self, *field_names) |
Returns a new QuerySet instance that will select only distinct results.
|
Returns a new QuerySet instance that will select only distinct results.
| def distinct(self, *field_names):
"""
Returns a new QuerySet instance that will select only distinct results.
"""
assert self.query.can_filter(), \
"Cannot create distinct fields once a slice has been taken."
obj = self._clone()
obj.query.add_distinct_fields(*... | [
"def",
"distinct",
"(",
"self",
",",
"*",
"field_names",
")",
":",
"assert",
"self",
".",
"query",
".",
"can_filter",
"(",
")",
",",
"\"Cannot create distinct fields once a slice has been taken.\"",
"obj",
"=",
"self",
".",
"_clone",
"(",
")",
"obj",
".",
"que... | [
825,
4
] | [
833,
18
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.extra | (self, select=None, where=None, params=None, tables=None,
order_by=None, select_params=None) |
Adds extra SQL fragments to the query.
|
Adds extra SQL fragments to the query.
| def extra(self, select=None, where=None, params=None, tables=None,
order_by=None, select_params=None):
"""
Adds extra SQL fragments to the query.
"""
assert self.query.can_filter(), \
"Cannot change a query once a slice has been taken"
clone = self._clon... | [
"def",
"extra",
"(",
"self",
",",
"select",
"=",
"None",
",",
"where",
"=",
"None",
",",
"params",
"=",
"None",
",",
"tables",
"=",
"None",
",",
"order_by",
"=",
"None",
",",
"select_params",
"=",
"None",
")",
":",
"assert",
"self",
".",
"query",
"... | [
835,
4
] | [
844,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.reverse | (self) |
Reverses the ordering of the QuerySet.
|
Reverses the ordering of the QuerySet.
| def reverse(self):
"""
Reverses the ordering of the QuerySet.
"""
clone = self._clone()
clone.query.standard_ordering = not clone.query.standard_ordering
return clone | [
"def",
"reverse",
"(",
"self",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"clone",
".",
"query",
".",
"standard_ordering",
"=",
"not",
"clone",
".",
"query",
".",
"standard_ordering",
"return",
"clone"
] | [
846,
4
] | [
852,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.defer | (self, *fields) |
Defers the loading of data for certain fields until they are accessed.
The set of fields to defer is added to any existing set of deferred
fields. The only exception to this is if None is passed in as the only
parameter, in which case all deferrals are removed (None acts as a
re... |
Defers the loading of data for certain fields until they are accessed.
The set of fields to defer is added to any existing set of deferred
fields. The only exception to this is if None is passed in as the only
parameter, in which case all deferrals are removed (None acts as a
re... | def defer(self, *fields):
"""
Defers the loading of data for certain fields until they are accessed.
The set of fields to defer is added to any existing set of deferred
fields. The only exception to this is if None is passed in as the only
parameter, in which case all deferrals a... | [
"def",
"defer",
"(",
"self",
",",
"*",
"fields",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"if",
"fields",
"==",
"(",
"None",
",",
")",
":",
"clone",
".",
"query",
".",
"clear_deferred_loading",
"(",
")",
"else",
":",
"clone",
".",
... | [
854,
4
] | [
867,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.only | (self, *fields) |
Essentially, the opposite of defer. Only the fields passed into this
method and that are not already specified as deferred are loaded
immediately when the queryset is evaluated.
|
Essentially, the opposite of defer. Only the fields passed into this
method and that are not already specified as deferred are loaded
immediately when the queryset is evaluated.
| def only(self, *fields):
"""
Essentially, the opposite of defer. Only the fields passed into this
method and that are not already specified as deferred are loaded
immediately when the queryset is evaluated.
"""
if fields == (None,):
# Can only pass None to def... | [
"def",
"only",
"(",
"self",
",",
"*",
"fields",
")",
":",
"if",
"fields",
"==",
"(",
"None",
",",
")",
":",
"# Can only pass None to defer(), not only(), as the rest option.",
"# That won't stop people trying to do this, so let's be explicit.",
"raise",
"TypeError",
"(",
... | [
869,
4
] | [
881,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.using | (self, alias) |
Selects which database this QuerySet should execute its query against.
|
Selects which database this QuerySet should execute its query against.
| def using(self, alias):
"""
Selects which database this QuerySet should execute its query against.
"""
clone = self._clone()
clone._db = alias
return clone | [
"def",
"using",
"(",
"self",
",",
"alias",
")",
":",
"clone",
"=",
"self",
".",
"_clone",
"(",
")",
"clone",
".",
"_db",
"=",
"alias",
"return",
"clone"
] | [
883,
4
] | [
889,
20
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.ordered | (self) |
Returns True if the QuerySet is ordered -- i.e. has an order_by()
clause or a default ordering on the model.
|
Returns True if the QuerySet is ordered -- i.e. has an order_by()
clause or a default ordering on the model.
| def ordered(self):
"""
Returns True if the QuerySet is ordered -- i.e. has an order_by()
clause or a default ordering on the model.
"""
if self.query.extra_order_by or self.query.order_by:
return True
elif self.query.default_ordering and self.query.get_meta().... | [
"def",
"ordered",
"(",
"self",
")",
":",
"if",
"self",
".",
"query",
".",
"extra_order_by",
"or",
"self",
".",
"query",
".",
"order_by",
":",
"return",
"True",
"elif",
"self",
".",
"query",
".",
"default_ordering",
"and",
"self",
".",
"query",
".",
"ge... | [
895,
4
] | [
905,
24
] | python | en | ['en', 'error', 'th'] | False |
QuerySet.db | (self) | Return the database that will be used if this query is executed now | Return the database that will be used if this query is executed now | def db(self):
"Return the database that will be used if this query is executed now"
if self._for_write:
return self._db or router.db_for_write(self.model, **self._hints)
return self._db or router.db_for_read(self.model, **self._hints) | [
"def",
"db",
"(",
"self",
")",
":",
"if",
"self",
".",
"_for_write",
":",
"return",
"self",
".",
"_db",
"or",
"router",
".",
"db_for_write",
"(",
"self",
".",
"model",
",",
"*",
"*",
"self",
".",
"_hints",
")",
"return",
"self",
".",
"_db",
"or",
... | [
909,
4
] | [
913,
72
] | python | en | ['en', 'en', 'en'] | True |
QuerySet._insert | (self, objs, fields, return_id=False, raw=False, using=None) |
Inserts a new record for the given model. This provides an interface to
the InsertQuery class and is how Model.save() is implemented.
|
Inserts a new record for the given model. This provides an interface to
the InsertQuery class and is how Model.save() is implemented.
| def _insert(self, objs, fields, return_id=False, raw=False, using=None):
"""
Inserts a new record for the given model. This provides an interface to
the InsertQuery class and is how Model.save() is implemented.
"""
self._for_write = True
if using is None:
usin... | [
"def",
"_insert",
"(",
"self",
",",
"objs",
",",
"fields",
",",
"return_id",
"=",
"False",
",",
"raw",
"=",
"False",
",",
"using",
"=",
"None",
")",
":",
"self",
".",
"_for_write",
"=",
"True",
"if",
"using",
"is",
"None",
":",
"using",
"=",
"self"... | [
919,
4
] | [
929,
69
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._batched_insert | (self, objs, fields, batch_size) |
A little helper method for bulk_insert to insert the bulk one batch
at a time. Inserts recursively a batch from the front of the bulk and
then _batched_insert() the remaining objects again.
|
A little helper method for bulk_insert to insert the bulk one batch
at a time. Inserts recursively a batch from the front of the bulk and
then _batched_insert() the remaining objects again.
| def _batched_insert(self, objs, fields, batch_size):
"""
A little helper method for bulk_insert to insert the bulk one batch
at a time. Inserts recursively a batch from the front of the bulk and
then _batched_insert() the remaining objects again.
"""
if not objs:
... | [
"def",
"_batched_insert",
"(",
"self",
",",
"objs",
",",
"fields",
",",
"batch_size",
")",
":",
"if",
"not",
"objs",
":",
"return",
"ops",
"=",
"connections",
"[",
"self",
".",
"db",
"]",
".",
"ops",
"batch_size",
"=",
"(",
"batch_size",
"or",
"max",
... | [
933,
4
] | [
946,
59
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._next_is_sticky | (self) |
Indicates that the next filter call and the one following that should
be treated as a single filter. This is only important when it comes to
determining when to reuse tables for many-to-many filters. Required so
that we can filter naturally on the results of related managers.
T... |
Indicates that the next filter call and the one following that should
be treated as a single filter. This is only important when it comes to
determining when to reuse tables for many-to-many filters. Required so
that we can filter naturally on the results of related managers. | def _next_is_sticky(self):
"""
Indicates that the next filter call and the one following that should
be treated as a single filter. This is only important when it comes to
determining when to reuse tables for many-to-many filters. Required so
that we can filter naturally on the r... | [
"def",
"_next_is_sticky",
"(",
"self",
")",
":",
"self",
".",
"_sticky_filter",
"=",
"True",
"return",
"self"
] | [
978,
4
] | [
990,
19
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._merge_sanity_check | (self, other) |
Checks that we are merging two comparable QuerySet classes. By default
this does nothing, but see the ValuesQuerySet for an example of where
it's useful.
|
Checks that we are merging two comparable QuerySet classes. By default
this does nothing, but see the ValuesQuerySet for an example of where
it's useful.
| def _merge_sanity_check(self, other):
"""
Checks that we are merging two comparable QuerySet classes. By default
this does nothing, but see the ValuesQuerySet for an example of where
it's useful.
"""
pass | [
"def",
"_merge_sanity_check",
"(",
"self",
",",
"other",
")",
":",
"pass"
] | [
992,
4
] | [
998,
12
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._merge_known_related_objects | (self, other) |
Keep track of all known related objects from either QuerySet instance.
|
Keep track of all known related objects from either QuerySet instance.
| def _merge_known_related_objects(self, other):
"""
Keep track of all known related objects from either QuerySet instance.
"""
for field, objects in other._known_related_objects.items():
self._known_related_objects.setdefault(field, {}).update(objects) | [
"def",
"_merge_known_related_objects",
"(",
"self",
",",
"other",
")",
":",
"for",
"field",
",",
"objects",
"in",
"other",
".",
"_known_related_objects",
".",
"items",
"(",
")",
":",
"self",
".",
"_known_related_objects",
".",
"setdefault",
"(",
"field",
",",
... | [
1000,
4
] | [
1005,
77
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._setup_aggregate_query | (self, aggregates) |
Prepare the query for computing a result that contains aggregate annotations.
|
Prepare the query for computing a result that contains aggregate annotations.
| def _setup_aggregate_query(self, aggregates):
"""
Prepare the query for computing a result that contains aggregate annotations.
"""
opts = self.model._meta
if self.query.group_by is None:
field_names = [f.attname for f in opts.concrete_fields]
self.query.a... | [
"def",
"_setup_aggregate_query",
"(",
"self",
",",
"aggregates",
")",
":",
"opts",
"=",
"self",
".",
"model",
".",
"_meta",
"if",
"self",
".",
"query",
".",
"group_by",
"is",
"None",
":",
"field_names",
"=",
"[",
"f",
".",
"attname",
"for",
"f",
"in",
... | [
1007,
4
] | [
1015,
37
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._as_sql | (self, connection) |
Returns the internal query's SQL and parameters (as a tuple).
|
Returns the internal query's SQL and parameters (as a tuple).
| def _as_sql(self, connection):
"""
Returns the internal query's SQL and parameters (as a tuple).
"""
obj = self.values("pk")
if obj._db is None or connection == connections[obj._db]:
return obj.query.get_compiler(connection=connection).as_nested_sql()
raise Va... | [
"def",
"_as_sql",
"(",
"self",
",",
"connection",
")",
":",
"obj",
"=",
"self",
".",
"values",
"(",
"\"pk\"",
")",
"if",
"obj",
".",
"_db",
"is",
"None",
"or",
"connection",
"==",
"connections",
"[",
"obj",
".",
"_db",
"]",
":",
"return",
"obj",
".... | [
1020,
4
] | [
1027,
78
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._add_hints | (self, **hints) |
Update hinting information for later use by Routers
|
Update hinting information for later use by Routers
| def _add_hints(self, **hints):
"""
Update hinting information for later use by Routers
"""
# If there is any hinting information, add it to what we already know.
# If we have a new hint for an existing key, overwrite with the new value.
self._hints.update(hints) | [
"def",
"_add_hints",
"(",
"self",
",",
"*",
"*",
"hints",
")",
":",
"# If there is any hinting information, add it to what we already know.",
"# If we have a new hint for an existing key, overwrite with the new value.",
"self",
".",
"_hints",
".",
"update",
"(",
"hints",
")"
] | [
1033,
4
] | [
1039,
33
] | python | en | ['en', 'error', 'th'] | False |
QuerySet._has_filters | (self) |
Checks if this QuerySet has any filtering going on. Note that this
isn't equivalent for checking if all objects are present in results,
for example qs[1:]._has_filters() -> False.
|
Checks if this QuerySet has any filtering going on. Note that this
isn't equivalent for checking if all objects are present in results,
for example qs[1:]._has_filters() -> False.
| def _has_filters(self):
"""
Checks if this QuerySet has any filtering going on. Note that this
isn't equivalent for checking if all objects are present in results,
for example qs[1:]._has_filters() -> False.
"""
return self.query.has_filters() | [
"def",
"_has_filters",
"(",
"self",
")",
":",
"return",
"self",
".",
"query",
".",
"has_filters",
"(",
")"
] | [
1041,
4
] | [
1047,
39
] | python | en | ['en', 'error', 'th'] | False |
ValuesQuerySet._setup_query | (self) |
Constructs the field_names list that the values query will be
retrieving.
Called by the _clone() method after initializing the rest of the
instance.
|
Constructs the field_names list that the values query will be
retrieving. | def _setup_query(self):
"""
Constructs the field_names list that the values query will be
retrieving.
Called by the _clone() method after initializing the rest of the
instance.
"""
self.query.clear_deferred_loading()
self.query.clear_select_fields()
... | [
"def",
"_setup_query",
"(",
"self",
")",
":",
"self",
".",
"query",
".",
"clear_deferred_loading",
"(",
")",
"self",
".",
"query",
".",
"clear_select_fields",
"(",
")",
"if",
"self",
".",
"_fields",
":",
"self",
".",
"extra_names",
"=",
"[",
"]",
"self",... | [
1097,
4
] | [
1139,
63
] | python | en | ['en', 'error', 'th'] | False |
ValuesQuerySet._clone | (self, klass=None, setup=False, **kwargs) |
Cloning a ValuesQuerySet preserves the current fields.
|
Cloning a ValuesQuerySet preserves the current fields.
| def _clone(self, klass=None, setup=False, **kwargs):
"""
Cloning a ValuesQuerySet preserves the current fields.
"""
c = super(ValuesQuerySet, self)._clone(klass, **kwargs)
if not hasattr(c, '_fields'):
# Only clone self._fields if _fields wasn't passed into the clonin... | [
"def",
"_clone",
"(",
"self",
",",
"klass",
"=",
"None",
",",
"setup",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"c",
"=",
"super",
"(",
"ValuesQuerySet",
",",
"self",
")",
".",
"_clone",
"(",
"klass",
",",
"*",
"*",
"kwargs",
")",
"if",
... | [
1141,
4
] | [
1155,
16
] | python | en | ['en', 'error', 'th'] | False |
ValuesQuerySet._setup_aggregate_query | (self, aggregates) |
Prepare the query for computing a result that contains aggregate annotations.
|
Prepare the query for computing a result that contains aggregate annotations.
| def _setup_aggregate_query(self, aggregates):
"""
Prepare the query for computing a result that contains aggregate annotations.
"""
self.query.set_group_by()
if self.aggregate_names is not None:
self.aggregate_names.extend(aggregates)
self.query.set_aggre... | [
"def",
"_setup_aggregate_query",
"(",
"self",
",",
"aggregates",
")",
":",
"self",
".",
"query",
".",
"set_group_by",
"(",
")",
"if",
"self",
".",
"aggregate_names",
"is",
"not",
"None",
":",
"self",
".",
"aggregate_names",
".",
"extend",
"(",
"aggregates",
... | [
1165,
4
] | [
1175,
70
] | python | en | ['en', 'error', 'th'] | False |
ValuesQuerySet._as_sql | (self, connection) |
For ValuesQuerySet (and subclasses like ValuesListQuerySet), they can
only be used as nested queries if they're already set up to select only
a single field (in which case, that is the field column that is
returned). This differs from QuerySet.as_sql(), where the column to
selec... |
For ValuesQuerySet (and subclasses like ValuesListQuerySet), they can
only be used as nested queries if they're already set up to select only
a single field (in which case, that is the field column that is
returned). This differs from QuerySet.as_sql(), where the column to
selec... | def _as_sql(self, connection):
"""
For ValuesQuerySet (and subclasses like ValuesListQuerySet), they can
only be used as nested queries if they're already set up to select only
a single field (in which case, that is the field column that is
returned). This differs from QuerySet.a... | [
"def",
"_as_sql",
"(",
"self",
",",
"connection",
")",
":",
"if",
"(",
"(",
"self",
".",
"_fields",
"and",
"len",
"(",
"self",
".",
"_fields",
")",
">",
"1",
")",
"or",
"(",
"not",
"self",
".",
"_fields",
"and",
"len",
"(",
"self",
".",
"model",
... | [
1177,
4
] | [
1193,
78
] | python | en | ['en', 'error', 'th'] | False |
ValuesQuerySet._prepare | (self) |
Validates that we aren't trying to do a query like
value__in=qs.values('value1', 'value2'), which isn't valid.
|
Validates that we aren't trying to do a query like
value__in=qs.values('value1', 'value2'), which isn't valid.
| def _prepare(self):
"""
Validates that we aren't trying to do a query like
value__in=qs.values('value1', 'value2'), which isn't valid.
"""
if ((self._fields and len(self._fields) > 1) or
(not self._fields and len(self.model._meta.fields) > 1)):
raise T... | [
"def",
"_prepare",
"(",
"self",
")",
":",
"if",
"(",
"(",
"self",
".",
"_fields",
"and",
"len",
"(",
"self",
".",
"_fields",
")",
">",
"1",
")",
"or",
"(",
"not",
"self",
".",
"_fields",
"and",
"len",
"(",
"self",
".",
"model",
".",
"_meta",
".... | [
1195,
4
] | [
1204,
19
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.