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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
flatpage | (request, url) |
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
|
Public interface to the flat page view. | def flatpage(request, url):
"""
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.... | [
"def",
"flatpage",
"(",
"request",
",",
"url",
")",
":",
"if",
"not",
"url",
".",
"startswith",
"(",
"'/'",
")",
":",
"url",
"=",
"'/'",
"+",
"url",
"site_id",
"=",
"get_current_site",
"(",
"request",
")",
".",
"id",
"try",
":",
"f",
"=",
"get_obje... | [
21,
0
] | [
44,
38
] | python | en | ['en', 'error', 'th'] | False |
render_flatpage | (request, f) |
Internal interface to the flat page view.
|
Internal interface to the flat page view.
| def render_flatpage(request, f):
"""
Internal interface to the flat page view.
"""
# If registration is required for accessing this page, and the user isn't
# logged in, redirect to the login page.
if f.registration_required and not request.user.is_authenticated:
from django.contrib.auth... | [
"def",
"render_flatpage",
"(",
"request",
",",
"f",
")",
":",
"# If registration is required for accessing this page, and the user isn't",
"# logged in, redirect to the login page.",
"if",
"f",
".",
"registration_required",
"and",
"not",
"request",
".",
"user",
".",
"is_authe... | [
48,
0
] | [
68,
66
] | python | en | ['en', 'error', 'th'] | False |
update_last_login | (sender, user, **kwargs) |
A signal receiver which updates the last_login date for
the user logging in.
|
A signal receiver which updates the last_login date for
the user logging in.
| def update_last_login(sender, user, **kwargs):
"""
A signal receiver which updates the last_login date for
the user logging in.
"""
user.last_login = timezone.now()
user.save(update_fields=['last_login']) | [
"def",
"update_last_login",
"(",
"sender",
",",
"user",
",",
"*",
"*",
"kwargs",
")",
":",
"user",
".",
"last_login",
"=",
"timezone",
".",
"now",
"(",
")",
"user",
".",
"save",
"(",
"update_fields",
"=",
"[",
"'last_login'",
"]",
")"
] | [
13,
0
] | [
19,
43
] | python | en | ['en', 'error', 'th'] | False |
_user_has_perm | (user, perm, obj) |
A backend can raise `PermissionDenied` to short-circuit permission checking.
|
A backend can raise `PermissionDenied` to short-circuit permission checking.
| def _user_has_perm(user, perm, obj):
"""
A backend can raise `PermissionDenied` to short-circuit permission checking.
"""
for backend in auth.get_backends():
if not hasattr(backend, 'has_perm'):
continue
try:
if backend.has_perm(user, perm, obj):
r... | [
"def",
"_user_has_perm",
"(",
"user",
",",
"perm",
",",
"obj",
")",
":",
"for",
"backend",
"in",
"auth",
".",
"get_backends",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"backend",
",",
"'has_perm'",
")",
":",
"continue",
"try",
":",
"if",
"backend",
... | [
196,
0
] | [
208,
16
] | python | en | ['en', 'error', 'th'] | False |
_user_has_module_perms | (user, app_label) |
A backend can raise `PermissionDenied` to short-circuit permission checking.
|
A backend can raise `PermissionDenied` to short-circuit permission checking.
| def _user_has_module_perms(user, app_label):
"""
A backend can raise `PermissionDenied` to short-circuit permission checking.
"""
for backend in auth.get_backends():
if not hasattr(backend, 'has_module_perms'):
continue
try:
if backend.has_module_perms(user, app_l... | [
"def",
"_user_has_module_perms",
"(",
"user",
",",
"app_label",
")",
":",
"for",
"backend",
"in",
"auth",
".",
"get_backends",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"backend",
",",
"'has_module_perms'",
")",
":",
"continue",
"try",
":",
"if",
"backen... | [
211,
0
] | [
223,
16
] | python | en | ['en', 'error', 'th'] | False |
UserManager._create_user | (self, username, email, password, **extra_fields) |
Create and save a user with the given username, email, and password.
|
Create and save a user with the given username, email, and password.
| def _create_user(self, username, email, password, **extra_fields):
"""
Create and save a user with the given username, email, and password.
"""
if not username:
raise ValueError('The given username must be set')
email = self.normalize_email(email)
username = s... | [
"def",
"_create_user",
"(",
"self",
",",
"username",
",",
"email",
",",
"password",
",",
"*",
"*",
"extra_fields",
")",
":",
"if",
"not",
"username",
":",
"raise",
"ValueError",
"(",
"'The given username must be set'",
")",
"email",
"=",
"self",
".",
"normal... | [
130,
4
] | [
141,
19
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.get_user_permissions | (self, obj=None) |
Return a list of permission strings that this user has directly.
Query all available auth backends. If an object is passed in,
return only permissions matching this object.
|
Return a list of permission strings that this user has directly.
Query all available auth backends. If an object is passed in,
return only permissions matching this object.
| def get_user_permissions(self, obj=None):
"""
Return a list of permission strings that this user has directly.
Query all available auth backends. If an object is passed in,
return only permissions matching this object.
"""
return _user_get_permissions(self, obj, 'user') | [
"def",
"get_user_permissions",
"(",
"self",
",",
"obj",
"=",
"None",
")",
":",
"return",
"_user_get_permissions",
"(",
"self",
",",
"obj",
",",
"'user'",
")"
] | [
262,
4
] | [
268,
55
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.get_group_permissions | (self, obj=None) |
Return a list of permission strings that this user has through their
groups. Query all available auth backends. If an object is passed in,
return only permissions matching this object.
|
Return a list of permission strings that this user has through their
groups. Query all available auth backends. If an object is passed in,
return only permissions matching this object.
| def get_group_permissions(self, obj=None):
"""
Return a list of permission strings that this user has through their
groups. Query all available auth backends. If an object is passed in,
return only permissions matching this object.
"""
return _user_get_permissions(self, o... | [
"def",
"get_group_permissions",
"(",
"self",
",",
"obj",
"=",
"None",
")",
":",
"return",
"_user_get_permissions",
"(",
"self",
",",
"obj",
",",
"'group'",
")"
] | [
270,
4
] | [
276,
56
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.has_perm | (self, perm, obj=None) |
Return True if the user has the specified permission. Query all
available auth backends, but return immediately if any backend returns
True. Thus, a user who has permission from a single auth backend is
assumed to have permission in general. If an object is provided, check
permi... |
Return True if the user has the specified permission. Query all
available auth backends, but return immediately if any backend returns
True. Thus, a user who has permission from a single auth backend is
assumed to have permission in general. If an object is provided, check
permi... | def has_perm(self, perm, obj=None):
"""
Return True if the user has the specified permission. Query all
available auth backends, but return immediately if any backend returns
True. Thus, a user who has permission from a single auth backend is
assumed to have permission in general... | [
"def",
"has_perm",
"(",
"self",
",",
"perm",
",",
"obj",
"=",
"None",
")",
":",
"# Active superusers have all permissions.",
"if",
"self",
".",
"is_active",
"and",
"self",
".",
"is_superuser",
":",
"return",
"True",
"# Otherwise we need to check the backends.",
"ret... | [
281,
4
] | [
294,
46
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.has_perms | (self, perm_list, obj=None) |
Return True if the user has each of the specified permissions. If
object is passed, check if the user has all required perms for it.
|
Return True if the user has each of the specified permissions. If
object is passed, check if the user has all required perms for it.
| def has_perms(self, perm_list, obj=None):
"""
Return True if the user has each of the specified permissions. If
object is passed, check if the user has all required perms for it.
"""
return all(self.has_perm(perm, obj) for perm in perm_list) | [
"def",
"has_perms",
"(",
"self",
",",
"perm_list",
",",
"obj",
"=",
"None",
")",
":",
"return",
"all",
"(",
"self",
".",
"has_perm",
"(",
"perm",
",",
"obj",
")",
"for",
"perm",
"in",
"perm_list",
")"
] | [
296,
4
] | [
301,
66
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.has_module_perms | (self, app_label) |
Return True if the user has any permissions in the given app label.
Use similar logic as has_perm(), above.
|
Return True if the user has any permissions in the given app label.
Use similar logic as has_perm(), above.
| def has_module_perms(self, app_label):
"""
Return True if the user has any permissions in the given app label.
Use similar logic as has_perm(), above.
"""
# Active superusers have all permissions.
if self.is_active and self.is_superuser:
return True
r... | [
"def",
"has_module_perms",
"(",
"self",
",",
"app_label",
")",
":",
"# Active superusers have all permissions.",
"if",
"self",
".",
"is_active",
"and",
"self",
".",
"is_superuser",
":",
"return",
"True",
"return",
"_user_has_module_perms",
"(",
"self",
",",
"app_lab... | [
303,
4
] | [
312,
54
] | python | en | ['en', 'error', 'th'] | False |
AbstractUser.get_full_name | (self) |
Return the first_name plus the last_name, with a space in between.
|
Return the first_name plus the last_name, with a space in between.
| def get_full_name(self):
"""
Return the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip() | [
"def",
"get_full_name",
"(",
"self",
")",
":",
"full_name",
"=",
"'%s %s'",
"%",
"(",
"self",
".",
"first_name",
",",
"self",
".",
"last_name",
")",
"return",
"full_name",
".",
"strip",
"(",
")"
] | [
367,
4
] | [
372,
32
] | python | en | ['en', 'error', 'th'] | False |
AbstractUser.get_short_name | (self) | Return the short name for the user. | Return the short name for the user. | def get_short_name(self):
"""Return the short name for the user."""
return self.first_name | [
"def",
"get_short_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"first_name"
] | [
374,
4
] | [
376,
30
] | python | en | ['en', 'no', 'en'] | True |
AbstractUser.email_user | (self, subject, message, from_email=None, **kwargs) | Send an email to this user. | Send an email to this user. | def email_user(self, subject, message, from_email=None, **kwargs):
"""Send an email to this user."""
send_mail(subject, message, from_email, [self.email], **kwargs) | [
"def",
"email_user",
"(",
"self",
",",
"subject",
",",
"message",
",",
"from_email",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"send_mail",
"(",
"subject",
",",
"message",
",",
"from_email",
",",
"[",
"self",
".",
"email",
"]",
",",
"*",
"*",
... | [
378,
4
] | [
380,
71
] | python | en | ['en', 'en', 'en'] | True |
test_disallowed_methods | (all_user_types_api_client, list_url, detail_url) |
Tests that only safe methods are allowed to user list and detail endpoints.
|
Tests that only safe methods are allowed to user list and detail endpoints.
| def test_disallowed_methods(all_user_types_api_client, list_url, detail_url):
"""
Tests that only safe methods are allowed to user list and detail endpoints.
"""
check_only_safe_methods_allowed(all_user_types_api_client, (list_url, detail_url)) | [
"def",
"test_disallowed_methods",
"(",
"all_user_types_api_client",
",",
"list_url",
",",
"detail_url",
")",
":",
"check_only_safe_methods_allowed",
"(",
"all_user_types_api_client",
",",
"(",
"list_url",
",",
"detail_url",
")",
")"
] | [
22,
0
] | [
26,
86
] | python | en | ['en', 'error', 'th'] | False |
EmailBackend._get_filename | (self) | Return a unique file name. | Return a unique file name. | def _get_filename(self):
"""Return a unique file name."""
if self._fname is None:
timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
fname = "%s-%s.log" % (timestamp, abs(id(self)))
self._fname = os.path.join(self.file_path, fname)
return self._fnam... | [
"def",
"_get_filename",
"(",
"self",
")",
":",
"if",
"self",
".",
"_fname",
"is",
"None",
":",
"timestamp",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"\"%Y%m%d-%H%M%S\"",
")",
"fname",
"=",
"\"%s-%s.log\"",
"%",
"(",
... | [
49,
4
] | [
55,
26
] | python | en | ['fr', 'it', 'en'] | False |
csrf_failure | (request, reason="", template_name=CSRF_FAILURE_TEMPLATE_NAME) |
Default view used when request fails CSRF protection
|
Default view used when request fails CSRF protection
| def csrf_failure(request, reason="", template_name=CSRF_FAILURE_TEMPLATE_NAME):
"""
Default view used when request fails CSRF protection
"""
from django.middleware.csrf import REASON_NO_REFERER, REASON_NO_CSRF_COOKIE
c = {
'title': _("Forbidden"),
'main': _("CSRF verification failed.... | [
"def",
"csrf_failure",
"(",
"request",
",",
"reason",
"=",
"\"\"",
",",
"template_name",
"=",
"CSRF_FAILURE_TEMPLATE_NAME",
")",
":",
"from",
"django",
".",
"middleware",
".",
"csrf",
"import",
"REASON_NO_REFERER",
",",
"REASON_NO_CSRF_COOKIE",
"c",
"=",
"{",
"'... | [
103,
0
] | [
153,
71
] | python | en | ['en', 'error', 'th'] | False |
GenericRelationTests.test_inherited_models_content_type | (self) |
Test that GenericRelations on inherited classes use the correct content
type.
|
Test that GenericRelations on inherited classes use the correct content
type.
| def test_inherited_models_content_type(self):
"""
Test that GenericRelations on inherited classes use the correct content
type.
"""
p = Place.objects.create(name="South Park")
r = Restaurant.objects.create(name="Chubby's")
l1 = Link.objects.create(content_object=... | [
"def",
"test_inherited_models_content_type",
"(",
"self",
")",
":",
"p",
"=",
"Place",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"South Park\"",
")",
"r",
"=",
"Restaurant",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"Chubby's\"",
")",
"l1... | [
16,
4
] | [
27,
51
] | python | en | ['en', 'error', 'th'] | False |
GenericRelationTests.test_reverse_relation_pk | (self) |
Test that the correct column name is used for the primary key on the
originating model of a query. See #12664.
|
Test that the correct column name is used for the primary key on the
originating model of a query. See #12664.
| def test_reverse_relation_pk(self):
"""
Test that the correct column name is used for the primary key on the
originating model of a query. See #12664.
"""
p = Person.objects.create(account=23, name='Chef')
Address.objects.create(street='123 Anywhere Place',
... | [
"def",
"test_reverse_relation_pk",
"(",
"self",
")",
":",
"p",
"=",
"Person",
".",
"objects",
".",
"create",
"(",
"account",
"=",
"23",
",",
"name",
"=",
"'Chef'",
")",
"Address",
".",
"objects",
".",
"create",
"(",
"street",
"=",
"'123 Anywhere Place'",
... | [
29,
4
] | [
41,
44
] | python | en | ['en', 'error', 'th'] | False |
GenericRelationTests.test_q_object_or | (self) |
Tests that SQL query parameters for generic relations are properly
grouped when OR is used.
Test for bug http://code.djangoproject.com/ticket/11535
In this bug the first query (below) works while the second, with the
query parameters the same but in reverse order, does not.
... |
Tests that SQL query parameters for generic relations are properly
grouped when OR is used. | def test_q_object_or(self):
"""
Tests that SQL query parameters for generic relations are properly
grouped when OR is used.
Test for bug http://code.djangoproject.com/ticket/11535
In this bug the first query (below) works while the second, with the
query parameters the ... | [
"def",
"test_q_object_or",
"(",
"self",
")",
":",
"note_contact",
"=",
"Contact",
".",
"objects",
".",
"create",
"(",
")",
"org_contact",
"=",
"Contact",
".",
"objects",
".",
"create",
"(",
")",
"Note",
".",
"objects",
".",
"create",
"(",
"note",
"=",
... | [
53,
4
] | [
79,
42
] | python | en | ['en', 'error', 'th'] | False |
GenericRelationTests.test_generic_relation_ordering | (self) |
Test that ordering over a generic relation does not include extraneous
duplicate results, nor excludes rows not participating in the relation.
|
Test that ordering over a generic relation does not include extraneous
duplicate results, nor excludes rows not participating in the relation.
| def test_generic_relation_ordering(self):
"""
Test that ordering over a generic relation does not include extraneous
duplicate results, nor excludes rows not participating in the relation.
"""
p1 = Place.objects.create(name="South Park")
p2 = Place.objects.create(name="Th... | [
"def",
"test_generic_relation_ordering",
"(",
"self",
")",
":",
"p1",
"=",
"Place",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"South Park\"",
")",
"p2",
"=",
"Place",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"\"The City\"",
")",
"c",
"="... | [
89,
4
] | [
107,
45
] | python | en | ['en', 'error', 'th'] | False |
GenericRelationTests.test_target_model_is_unsaved | (self) | Test related to #13085 | Test related to #13085 | def test_target_model_is_unsaved(self):
"""Test related to #13085"""
# Fails with another, ORM-level error
dev1 = Developer(name='Joe')
note = Note(note='Deserves promotion', content_object=dev1)
self.assertRaises(IntegrityError, note.save) | [
"def",
"test_target_model_is_unsaved",
"(",
"self",
")",
":",
"# Fails with another, ORM-level error",
"dev1",
"=",
"Developer",
"(",
"name",
"=",
"'Joe'",
")",
"note",
"=",
"Note",
"(",
"note",
"=",
"'Deserves promotion'",
",",
"content_object",
"=",
"dev1",
")",... | [
109,
4
] | [
114,
52
] | python | en | ['en', 'en', 'en'] | True |
GenericRelationTests.test_target_model_len_zero | (self) | Test for #13085 -- __len__() returns 0 | Test for #13085 -- __len__() returns 0 | def test_target_model_len_zero(self):
"""Test for #13085 -- __len__() returns 0"""
team1 = Team.objects.create(name='Backend devs')
try:
note = Note(note='Deserve a bonus', content_object=team1)
except Exception as e:
if (issubclass(type(e), Exception) and
... | [
"def",
"test_target_model_len_zero",
"(",
"self",
")",
":",
"team1",
"=",
"Team",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"'Backend devs'",
")",
"try",
":",
"note",
"=",
"Note",
"(",
"note",
"=",
"'Deserve a bonus'",
",",
"content_object",
"=",
"t... | [
116,
4
] | [
127,
19
] | python | en | ['en', 'no', 'en'] | True |
GenericRelationTests.test_target_model_nonzero_false | (self) | Test related to #13085 | Test related to #13085 | def test_target_model_nonzero_false(self):
"""Test related to #13085"""
# __nonzero__() returns False -- This actually doesn't currently fail.
# This test validates that
g1 = Guild.objects.create(name='First guild')
note = Note(note='Note for guild', content_object=g1)
no... | [
"def",
"test_target_model_nonzero_false",
"(",
"self",
")",
":",
"# __nonzero__() returns False -- This actually doesn't currently fail.",
"# This test validates that",
"g1",
"=",
"Guild",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"'First guild'",
")",
"note",
"=",
... | [
129,
4
] | [
135,
19
] | python | en | ['en', 'en', 'en'] | True |
GenericRelationTests.test_gfk_to_model_with_empty_pk | (self) | Test related to #13085 | Test related to #13085 | def test_gfk_to_model_with_empty_pk(self):
"""Test related to #13085"""
# Saving model with GenericForeignKey to model instance with an
# empty CharField PK
b1 = Board.objects.create(name='')
tag = Tag(label='VP', content_object=b1)
tag.save() | [
"def",
"test_gfk_to_model_with_empty_pk",
"(",
"self",
")",
":",
"# Saving model with GenericForeignKey to model instance with an",
"# empty CharField PK",
"b1",
"=",
"Board",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"''",
")",
"tag",
"=",
"Tag",
"(",
"label",... | [
138,
4
] | [
144,
18
] | python | en | ['en', 'en', 'en'] | True |
BaseDatabaseSchemaEditor.execute | (self, sql, params=[]) |
Executes the given SQL statement, with optional parameters.
|
Executes the given SQL statement, with optional parameters.
| def execute(self, sql, params=[]):
"""
Executes the given SQL statement, with optional parameters.
"""
# Log the command we're running, then run it
logger.debug("%s; (params %r)" % (sql, params))
if self.collect_sql:
self.collected_sql.append((sql % tuple(map(... | [
"def",
"execute",
"(",
"self",
",",
"sql",
",",
"params",
"=",
"[",
"]",
")",
":",
"# Log the command we're running, then run it",
"logger",
".",
"debug",
"(",
"\"%s; (params %r)\"",
"%",
"(",
"sql",
",",
"params",
")",
")",
"if",
"self",
".",
"collect_sql",... | [
91,
4
] | [
101,
43
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.column_sql | (self, model, field, include_default=False) |
Takes a field and returns its column definition.
The field must already have had set_attributes_from_name called.
|
Takes a field and returns its column definition.
The field must already have had set_attributes_from_name called.
| def column_sql(self, model, field, include_default=False):
"""
Takes a field and returns its column definition.
The field must already have had set_attributes_from_name called.
"""
# Get the column's type and use that as the basis of the SQL
db_params = field.db_parameter... | [
"def",
"column_sql",
"(",
"self",
",",
"model",
",",
"field",
",",
"include_default",
"=",
"False",
")",
":",
"# Get the column's type and use that as the basis of the SQL",
"db_params",
"=",
"field",
".",
"db_parameters",
"(",
"connection",
"=",
"self",
".",
"conne... | [
108,
4
] | [
153,
26
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.skip_default | (self, field) |
Some backends don't accept default values for certain columns types
(i.e. MySQL longtext and longblob).
|
Some backends don't accept default values for certain columns types
(i.e. MySQL longtext and longblob).
| def skip_default(self, field):
"""
Some backends don't accept default values for certain columns types
(i.e. MySQL longtext and longblob).
"""
return False | [
"def",
"skip_default",
"(",
"self",
",",
"field",
")",
":",
"return",
"False"
] | [
155,
4
] | [
160,
20
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.prepare_default | (self, value) |
Only used for backends which have requires_literal_defaults feature
|
Only used for backends which have requires_literal_defaults feature
| def prepare_default(self, value):
"""
Only used for backends which have requires_literal_defaults feature
"""
raise NotImplementedError(
'subclasses of BaseDatabaseSchemaEditor for backends which have '
'requires_literal_defaults must provide a prepare_default() m... | [
"def",
"prepare_default",
"(",
"self",
",",
"value",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of BaseDatabaseSchemaEditor for backends which have '",
"'requires_literal_defaults must provide a prepare_default() method'",
")"
] | [
162,
4
] | [
169,
9
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.effective_default | (self, field) |
Returns a field's effective database default value
|
Returns a field's effective database default value
| def effective_default(self, field):
"""
Returns a field's effective database default value
"""
if field.has_default():
default = field.get_default()
elif not field.null and field.blank and field.empty_strings_allowed:
if field.get_internal_type() == "Binar... | [
"def",
"effective_default",
"(",
"self",
",",
"field",
")",
":",
"if",
"field",
".",
"has_default",
"(",
")",
":",
"default",
"=",
"field",
".",
"get_default",
"(",
")",
"elif",
"not",
"field",
".",
"null",
"and",
"field",
".",
"blank",
"and",
"field",... | [
171,
4
] | [
190,
22
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.quote_value | (self, value) |
Returns a quoted version of the value so it's safe to use in an SQL
string. This is not safe against injection from user code; it is
intended only for use in making SQL scripts or preparing default values
for particularly tricky backends (defaults are not user-defined, though,
s... |
Returns a quoted version of the value so it's safe to use in an SQL
string. This is not safe against injection from user code; it is
intended only for use in making SQL scripts or preparing default values
for particularly tricky backends (defaults are not user-defined, though,
s... | def quote_value(self, value):
"""
Returns a quoted version of the value so it's safe to use in an SQL
string. This is not safe against injection from user code; it is
intended only for use in making SQL scripts or preparing default values
for particularly tricky backends (default... | [
"def",
"quote_value",
"(",
"self",
",",
"value",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
192,
4
] | [
200,
35
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.create_model | (self, model) |
Takes a model and creates a table for it in the database.
Will also create any accompanying indexes or unique constraints.
|
Takes a model and creates a table for it in the database.
Will also create any accompanying indexes or unique constraints.
| def create_model(self, model):
"""
Takes a model and creates a table for it in the database.
Will also create any accompanying indexes or unique constraints.
"""
# Create column SQL, add FK deferreds if needed
column_sqls = []
params = []
for field in mode... | [
"def",
"create_model",
"(",
"self",
",",
"model",
")",
":",
"# Create column SQL, add FK deferreds if needed",
"column_sqls",
"=",
"[",
"]",
"params",
"=",
"[",
"]",
"for",
"field",
"in",
"model",
".",
"_meta",
".",
"local_fields",
":",
"# SQL",
"definition",
... | [
204,
4
] | [
269,
52
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.delete_model | (self, model) |
Deletes a model from the database.
|
Deletes a model from the database.
| def delete_model(self, model):
"""
Deletes a model from the database.
"""
# Handle auto-created intermediary models
for field in model._meta.local_many_to_many:
if field.rel.through._meta.auto_created:
self.delete_model(field.rel.through)
# De... | [
"def",
"delete_model",
"(",
"self",
",",
"model",
")",
":",
"# Handle auto-created intermediary models",
"for",
"field",
"in",
"model",
".",
"_meta",
".",
"local_many_to_many",
":",
"if",
"field",
".",
"rel",
".",
"through",
".",
"_meta",
".",
"auto_created",
... | [
271,
4
] | [
283,
10
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.alter_unique_together | (self, model, old_unique_together, new_unique_together) |
Deals with a model changing its unique_together.
Note: The input unique_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
|
Deals with a model changing its unique_together.
Note: The input unique_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
| def alter_unique_together(self, model, old_unique_together, new_unique_together):
"""
Deals with a model changing its unique_together.
Note: The input unique_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
"""
olds = set(tuple(fields) for fi... | [
"def",
"alter_unique_together",
"(",
"self",
",",
"model",
",",
"old_unique_together",
",",
"new_unique_together",
")",
":",
"olds",
"=",
"set",
"(",
"tuple",
"(",
"fields",
")",
"for",
"fields",
"in",
"old_unique_together",
")",
"news",
"=",
"set",
"(",
"tu... | [
285,
4
] | [
307,
65
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.alter_index_together | (self, model, old_index_together, new_index_together) |
Deals with a model changing its index_together.
Note: The input index_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
|
Deals with a model changing its index_together.
Note: The input index_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
| def alter_index_together(self, model, old_index_together, new_index_together):
"""
Deals with a model changing its index_together.
Note: The input index_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
"""
olds = set(tuple(fields) for fields ... | [
"def",
"alter_index_together",
"(",
"self",
",",
"model",
",",
"old_index_together",
",",
"new_index_together",
")",
":",
"olds",
"=",
"set",
"(",
"tuple",
"(",
"fields",
")",
"for",
"fields",
"in",
"old_index_together",
")",
"news",
"=",
"set",
"(",
"tuple"... | [
309,
4
] | [
331,
78
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.alter_db_table | (self, model, old_db_table, new_db_table) |
Renames the table a model points to.
|
Renames the table a model points to.
| def alter_db_table(self, model, old_db_table, new_db_table):
"""
Renames the table a model points to.
"""
if old_db_table == new_db_table:
return
self.execute(self.sql_rename_table % {
"old_table": self.quote_name(old_db_table),
"new_table": se... | [
"def",
"alter_db_table",
"(",
"self",
",",
"model",
",",
"old_db_table",
",",
"new_db_table",
")",
":",
"if",
"old_db_table",
"==",
"new_db_table",
":",
"return",
"self",
".",
"execute",
"(",
"self",
".",
"sql_rename_table",
"%",
"{",
"\"old_table\"",
":",
"... | [
333,
4
] | [
342,
10
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.alter_db_tablespace | (self, model, old_db_tablespace, new_db_tablespace) |
Moves a model's table between tablespaces
|
Moves a model's table between tablespaces
| def alter_db_tablespace(self, model, old_db_tablespace, new_db_tablespace):
"""
Moves a model's table between tablespaces
"""
self.execute(self.sql_retablespace_table % {
"table": self.quote_name(model._meta.db_table),
"old_tablespace": self.quote_name(old_db_tabl... | [
"def",
"alter_db_tablespace",
"(",
"self",
",",
"model",
",",
"old_db_tablespace",
",",
"new_db_tablespace",
")",
":",
"self",
".",
"execute",
"(",
"self",
".",
"sql_retablespace_table",
"%",
"{",
"\"table\"",
":",
"self",
".",
"quote_name",
"(",
"model",
".",... | [
344,
4
] | [
352,
10
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.add_field | (self, model, field) |
Creates a field on a model.
Usually involves adding a column, but may involve adding a
table instead (for M2M fields)
|
Creates a field on a model.
Usually involves adding a column, but may involve adding a
table instead (for M2M fields)
| def add_field(self, model, field):
"""
Creates a field on a model.
Usually involves adding a column, but may involve adding a
table instead (for M2M fields)
"""
# Special-case implicit M2M tables
if isinstance(field, ManyToManyField) and field.rel.through._meta.au... | [
"def",
"add_field",
"(",
"self",
",",
"model",
",",
"field",
")",
":",
"# Special-case implicit M2M tables",
"if",
"isinstance",
"(",
"field",
",",
"ManyToManyField",
")",
"and",
"field",
".",
"rel",
".",
"through",
".",
"_meta",
".",
"auto_created",
":",
"r... | [
354,
4
] | [
397,
35
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.remove_field | (self, model, field) |
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
|
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
| def remove_field(self, model, field):
"""
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
"""
# Special-case implicit M2M tables
if isinstance(field, ManyToManyField) and field.rel.through._meta.auto_created:
... | [
"def",
"remove_field",
"(",
"self",
",",
"model",
",",
"field",
")",
":",
"# Special-case implicit M2M tables",
"if",
"isinstance",
"(",
"field",
",",
"ManyToManyField",
")",
"and",
"field",
".",
"rel",
".",
"through",
".",
"_meta",
".",
"auto_created",
":",
... | [
399,
4
] | [
423,
35
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor.alter_field | (self, model, old_field, new_field, strict=False) |
Allows a field's type, uniqueness, nullability, default, column,
constraints etc. to be modified.
Requires a copy of the old field as well so we can only perform
changes that are required.
If strict is true, raises errors if the old column does not match old_field precisely.
... |
Allows a field's type, uniqueness, nullability, default, column,
constraints etc. to be modified.
Requires a copy of the old field as well so we can only perform
changes that are required.
If strict is true, raises errors if the old column does not match old_field precisely.
... | def alter_field(self, model, old_field, new_field, strict=False):
"""
Allows a field's type, uniqueness, nullability, default, column,
constraints etc. to be modified.
Requires a copy of the old field as well so we can only perform
changes that are required.
If strict is ... | [
"def",
"alter_field",
"(",
"self",
",",
"model",
",",
"old_field",
",",
"new_field",
",",
"strict",
"=",
"False",
")",
":",
"# Ensure this field is even column-based",
"old_db_params",
"=",
"old_field",
".",
"db_parameters",
"(",
"connection",
"=",
"self",
".",
... | [
425,
4
] | [
463,
63
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor._alter_field | (self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False) | Actually perform a "physical" (non-ManyToMany) field update. | Actually perform a "physical" (non-ManyToMany) field update. | def _alter_field(self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False):
"""Actually perform a "physical" (non-ManyToMany) field update."""
# Has unique been removed?
if old_field.unique and (not new_field.unique or (not old_field... | [
"def",
"_alter_field",
"(",
"self",
",",
"model",
",",
"old_field",
",",
"new_field",
",",
"old_type",
",",
"new_type",
",",
"old_db_params",
",",
"new_db_params",
",",
"strict",
"=",
"False",
")",
":",
"# Has unique been removed?",
"if",
"old_field",
".",
"un... | [
465,
4
] | [
724,
35
] | python | en | ['en', 'en', 'en'] | True |
BaseDatabaseSchemaEditor._alter_column_type_sql | (self, table, column, type) |
Hook to specialize column type alteration for different backends,
for cases when a creation type is different to an alteration type
(e.g. SERIAL in PostgreSQL, PostGIS fields).
Should return two things; an SQL fragment of (sql, params) to insert
into an ALTER TABLE statement, a... |
Hook to specialize column type alteration for different backends,
for cases when a creation type is different to an alteration type
(e.g. SERIAL in PostgreSQL, PostGIS fields). | def _alter_column_type_sql(self, table, column, type):
"""
Hook to specialize column type alteration for different backends,
for cases when a creation type is different to an alteration type
(e.g. SERIAL in PostgreSQL, PostGIS fields).
Should return two things; an SQL fragment o... | [
"def",
"_alter_column_type_sql",
"(",
"self",
",",
"table",
",",
"column",
",",
"type",
")",
":",
"return",
"(",
"(",
"self",
".",
"sql_alter_column_type",
"%",
"{",
"\"column\"",
":",
"self",
".",
"quote_name",
"(",
"column",
")",
",",
"\"type\"",
":",
... | [
726,
4
] | [
745,
9
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor._alter_many_to_many | (self, model, old_field, new_field, strict) |
Alters M2Ms to repoint their to= endpoints.
|
Alters M2Ms to repoint their to= endpoints.
| def _alter_many_to_many(self, model, old_field, new_field, strict):
"""
Alters M2Ms to repoint their to= endpoints.
"""
# Rename the through table
if old_field.rel.through._meta.db_table != new_field.rel.through._meta.db_table:
self.alter_db_table(old_field.rel.throug... | [
"def",
"_alter_many_to_many",
"(",
"self",
",",
"model",
",",
"old_field",
",",
"new_field",
",",
"strict",
")",
":",
"# Rename the through table",
"if",
"old_field",
".",
"rel",
".",
"through",
".",
"_meta",
".",
"db_table",
"!=",
"new_field",
".",
"rel",
"... | [
747,
4
] | [
768,
9
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor._create_index_name | (self, model, column_names, suffix="") |
Generates a unique name for an index/unique constraint.
|
Generates a unique name for an index/unique constraint.
| def _create_index_name(self, model, column_names, suffix=""):
"""
Generates a unique name for an index/unique constraint.
"""
# If there is just one column in the index, use a default algorithm from Django
if len(column_names) == 1 and not suffix:
return truncate_name... | [
"def",
"_create_index_name",
"(",
"self",
",",
"model",
",",
"column_names",
",",
"suffix",
"=",
"\"\"",
")",
":",
"# If there is just one column in the index, use a default algorithm from Django",
"if",
"len",
"(",
"column_names",
")",
"==",
"1",
"and",
"not",
"suffi... | [
770,
4
] | [
800,
25
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseSchemaEditor._constraint_names | (self, model, column_names=None, unique=None,
primary_key=None, index=None, foreign_key=None,
check=None) |
Returns all constraint names matching the columns and conditions
|
Returns all constraint names matching the columns and conditions
| def _constraint_names(self, model, column_names=None, unique=None,
primary_key=None, index=None, foreign_key=None,
check=None):
"""
Returns all constraint names matching the columns and conditions
"""
column_names = list(column_names) i... | [
"def",
"_constraint_names",
"(",
"self",
",",
"model",
",",
"column_names",
"=",
"None",
",",
"unique",
"=",
"None",
",",
"primary_key",
"=",
"None",
",",
"index",
"=",
"None",
",",
"foreign_key",
"=",
"None",
",",
"check",
"=",
"None",
")",
":",
"colu... | [
842,
4
] | [
865,
21
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.formfield_for_dbfield | (self, db_field, request, **kwargs) |
Hook for specifying the form Field instance for a given database Field
instance.
If kwargs are given, they're passed to the form Field's constructor.
|
Hook for specifying the form Field instance for a given database Field
instance. | def formfield_for_dbfield(self, db_field, request, **kwargs):
"""
Hook for specifying the form Field instance for a given database Field
instance.
If kwargs are given, they're passed to the form Field's constructor.
"""
# If the field specifies choices, we don't need to ... | [
"def",
"formfield_for_dbfield",
"(",
"self",
",",
"db_field",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# If the field specifies choices, we don't need to look for special",
"# admin widgets - we just need to use a select widget of some kind.",
"if",
"db_field",
".",
... | [
130,
4
] | [
185,
43
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.formfield_for_choice_field | (self, db_field, request, **kwargs) |
Get a form Field for a database Field that has declared choices.
|
Get a form Field for a database Field that has declared choices.
| def formfield_for_choice_field(self, db_field, request, **kwargs):
"""
Get a form Field for a database Field that has declared choices.
"""
# If the field is named as a radio_field, use a RadioSelect
if db_field.name in self.radio_fields:
# Avoid stomping on custom wi... | [
"def",
"formfield_for_choice_field",
"(",
"self",
",",
"db_field",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# If the field is named as a radio_field, use a RadioSelect",
"if",
"db_field",
".",
"name",
"in",
"self",
".",
"radio_fields",
":",
"# Avoid stompin... | [
187,
4
] | [
203,
43
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_field_queryset | (self, db, db_field, request) |
If the ModelAdmin specifies ordering, the queryset should respect that
ordering. Otherwise don't specify the queryset, let the field decide
(return None in that case).
|
If the ModelAdmin specifies ordering, the queryset should respect that
ordering. Otherwise don't specify the queryset, let the field decide
(return None in that case).
| def get_field_queryset(self, db, db_field, request):
"""
If the ModelAdmin specifies ordering, the queryset should respect that
ordering. Otherwise don't specify the queryset, let the field decide
(return None in that case).
"""
related_admin = self.admin_site._registry.... | [
"def",
"get_field_queryset",
"(",
"self",
",",
"db",
",",
"db_field",
",",
"request",
")",
":",
"related_admin",
"=",
"self",
".",
"admin_site",
".",
"_registry",
".",
"get",
"(",
"db_field",
".",
"remote_field",
".",
"model",
")",
"if",
"related_admin",
"... | [
205,
4
] | [
216,
19
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.formfield_for_foreignkey | (self, db_field, request, **kwargs) |
Get a form Field for a ForeignKey.
|
Get a form Field for a ForeignKey.
| def formfield_for_foreignkey(self, db_field, request, **kwargs):
"""
Get a form Field for a ForeignKey.
"""
db = kwargs.get('using')
if 'widget' not in kwargs:
if db_field.name in self.get_autocomplete_fields(request):
kwargs['widget'] = AutocompleteS... | [
"def",
"formfield_for_foreignkey",
"(",
"self",
",",
"db_field",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"db",
"=",
"kwargs",
".",
"get",
"(",
"'using'",
")",
"if",
"'widget'",
"not",
"in",
"kwargs",
":",
"if",
"db_field",
".",
"name",
"in",... | [
218,
4
] | [
240,
43
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.formfield_for_manytomany | (self, db_field, request, **kwargs) |
Get a form Field for a ManyToManyField.
|
Get a form Field for a ManyToManyField.
| def formfield_for_manytomany(self, db_field, request, **kwargs):
"""
Get a form Field for a ManyToManyField.
"""
# If it uses an intermediary model that isn't auto created, don't show
# a field in admin.
if not db_field.remote_field.through._meta.auto_created:
... | [
"def",
"formfield_for_manytomany",
"(",
"self",
",",
"db_field",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# If it uses an intermediary model that isn't auto created, don't show",
"# a field in admin.",
"if",
"not",
"db_field",
".",
"remote_field",
".",
"through... | [
242,
4
] | [
274,
25
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_autocomplete_fields | (self, request) |
Return a list of ForeignKey and/or ManyToMany fields which should use
an autocomplete widget.
|
Return a list of ForeignKey and/or ManyToMany fields which should use
an autocomplete widget.
| def get_autocomplete_fields(self, request):
"""
Return a list of ForeignKey and/or ManyToMany fields which should use
an autocomplete widget.
"""
return self.autocomplete_fields | [
"def",
"get_autocomplete_fields",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"autocomplete_fields"
] | [
276,
4
] | [
281,
39
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_empty_value_display | (self) |
Return the empty_value_display set on ModelAdmin or AdminSite.
|
Return the empty_value_display set on ModelAdmin or AdminSite.
| def get_empty_value_display(self):
"""
Return the empty_value_display set on ModelAdmin or AdminSite.
"""
try:
return mark_safe(self.empty_value_display)
except AttributeError:
return mark_safe(self.admin_site.empty_value_display) | [
"def",
"get_empty_value_display",
"(",
"self",
")",
":",
"try",
":",
"return",
"mark_safe",
"(",
"self",
".",
"empty_value_display",
")",
"except",
"AttributeError",
":",
"return",
"mark_safe",
"(",
"self",
".",
"admin_site",
".",
"empty_value_display",
")"
] | [
296,
4
] | [
303,
65
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_exclude | (self, request, obj=None) |
Hook for specifying exclude.
|
Hook for specifying exclude.
| def get_exclude(self, request, obj=None):
"""
Hook for specifying exclude.
"""
return self.exclude | [
"def",
"get_exclude",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"return",
"self",
".",
"exclude"
] | [
305,
4
] | [
309,
27
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_fields | (self, request, obj=None) |
Hook for specifying fields.
|
Hook for specifying fields.
| def get_fields(self, request, obj=None):
"""
Hook for specifying fields.
"""
if self.fields:
return self.fields
# _get_form_for_get_fields() is implemented in subclasses.
form = self._get_form_for_get_fields(request, obj)
return [*form.base_fields, *se... | [
"def",
"get_fields",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"if",
"self",
".",
"fields",
":",
"return",
"self",
".",
"fields",
"# _get_form_for_get_fields() is implemented in subclasses.",
"form",
"=",
"self",
".",
"_get_form_for_get_field... | [
311,
4
] | [
319,
75
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_fieldsets | (self, request, obj=None) |
Hook for specifying fieldsets.
|
Hook for specifying fieldsets.
| def get_fieldsets(self, request, obj=None):
"""
Hook for specifying fieldsets.
"""
if self.fieldsets:
return self.fieldsets
return [(None, {'fields': self.get_fields(request, obj)})] | [
"def",
"get_fieldsets",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"if",
"self",
".",
"fieldsets",
":",
"return",
"self",
".",
"fieldsets",
"return",
"[",
"(",
"None",
",",
"{",
"'fields'",
":",
"self",
".",
"get_fields",
"(",
"r... | [
321,
4
] | [
327,
66
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_inlines | (self, request, obj) | Hook for specifying custom inlines. | Hook for specifying custom inlines. | def get_inlines(self, request, obj):
"""Hook for specifying custom inlines."""
return self.inlines | [
"def",
"get_inlines",
"(",
"self",
",",
"request",
",",
"obj",
")",
":",
"return",
"self",
".",
"inlines"
] | [
329,
4
] | [
331,
27
] | python | en | ['en', 'en', 'en'] | True |
BaseModelAdmin.get_ordering | (self, request) |
Hook for specifying field ordering.
|
Hook for specifying field ordering.
| def get_ordering(self, request):
"""
Hook for specifying field ordering.
"""
return self.ordering or () | [
"def",
"get_ordering",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"ordering",
"or",
"(",
")"
] | [
333,
4
] | [
337,
34
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_readonly_fields | (self, request, obj=None) |
Hook for specifying custom readonly fields.
|
Hook for specifying custom readonly fields.
| def get_readonly_fields(self, request, obj=None):
"""
Hook for specifying custom readonly fields.
"""
return self.readonly_fields | [
"def",
"get_readonly_fields",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"return",
"self",
".",
"readonly_fields"
] | [
339,
4
] | [
343,
35
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_prepopulated_fields | (self, request, obj=None) |
Hook for specifying custom prepopulated fields.
|
Hook for specifying custom prepopulated fields.
| def get_prepopulated_fields(self, request, obj=None):
"""
Hook for specifying custom prepopulated fields.
"""
return self.prepopulated_fields | [
"def",
"get_prepopulated_fields",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"return",
"self",
".",
"prepopulated_fields"
] | [
345,
4
] | [
349,
39
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_queryset | (self, request) |
Return a QuerySet of all model instances that can be edited by the
admin site. This is used by changelist_view.
|
Return a QuerySet of all model instances that can be edited by the
admin site. This is used by changelist_view.
| def get_queryset(self, request):
"""
Return a QuerySet of all model instances that can be edited by the
admin site. This is used by changelist_view.
"""
qs = self.model._default_manager.get_queryset()
# TODO: this should be handled by some parameter to the ChangeList.
... | [
"def",
"get_queryset",
"(",
"self",
",",
"request",
")",
":",
"qs",
"=",
"self",
".",
"model",
".",
"_default_manager",
".",
"get_queryset",
"(",
")",
"# TODO: this should be handled by some parameter to the ChangeList.",
"ordering",
"=",
"self",
".",
"get_ordering",
... | [
351,
4
] | [
361,
17
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.get_sortable_by | (self, request) | Hook for specifying which fields can be sorted in the changelist. | Hook for specifying which fields can be sorted in the changelist. | def get_sortable_by(self, request):
"""Hook for specifying which fields can be sorted in the changelist."""
return self.sortable_by if self.sortable_by is not None else self.get_list_display(request) | [
"def",
"get_sortable_by",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"sortable_by",
"if",
"self",
".",
"sortable_by",
"is",
"not",
"None",
"else",
"self",
".",
"get_list_display",
"(",
"request",
")"
] | [
363,
4
] | [
365,
99
] | python | en | ['en', 'en', 'en'] | True |
BaseModelAdmin.to_field_allowed | (self, request, to_field) |
Return True if the model associated with this admin should be
allowed to be referenced by the specified field.
|
Return True if the model associated with this admin should be
allowed to be referenced by the specified field.
| def to_field_allowed(self, request, to_field):
"""
Return True if the model associated with this admin should be
allowed to be referenced by the specified field.
"""
opts = self.model._meta
try:
field = opts.get_field(to_field)
except FieldDoesNotExis... | [
"def",
"to_field_allowed",
"(",
"self",
",",
"request",
",",
"to_field",
")",
":",
"opts",
"=",
"self",
".",
"model",
".",
"_meta",
"try",
":",
"field",
"=",
"opts",
".",
"get_field",
"(",
"to_field",
")",
"except",
"FieldDoesNotExist",
":",
"return",
"F... | [
421,
4
] | [
464,
20
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.has_add_permission | (self, request) |
Return True if the given request has permission to add an object.
Can be overridden by the user in subclasses.
|
Return True if the given request has permission to add an object.
Can be overridden by the user in subclasses.
| def has_add_permission(self, request):
"""
Return True if the given request has permission to add an object.
Can be overridden by the user in subclasses.
"""
opts = self.opts
codename = get_permission_codename('add', opts)
return request.user.has_perm("%s.%s" % (o... | [
"def",
"has_add_permission",
"(",
"self",
",",
"request",
")",
":",
"opts",
"=",
"self",
".",
"opts",
"codename",
"=",
"get_permission_codename",
"(",
"'add'",
",",
"opts",
")",
"return",
"request",
".",
"user",
".",
"has_perm",
"(",
"\"%s.%s\"",
"%",
"(",... | [
466,
4
] | [
473,
74
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.has_change_permission | (self, request, obj=None) |
Return True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to chan... |
Return True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter. | def has_change_permission(self, request, obj=None):
"""
Return True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
... | [
"def",
"has_change_permission",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"opts",
"=",
"self",
".",
"opts",
"codename",
"=",
"get_permission_codename",
"(",
"'change'",
",",
"opts",
")",
"return",
"request",
".",
"user",
".",
"has_per... | [
475,
4
] | [
488,
74
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.has_delete_permission | (self, request, obj=None) |
Return True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to dele... |
Return True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter. | def has_delete_permission(self, request, obj=None):
"""
Return True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
... | [
"def",
"has_delete_permission",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"opts",
"=",
"self",
".",
"opts",
"codename",
"=",
"get_permission_codename",
"(",
"'delete'",
",",
"opts",
")",
"return",
"request",
".",
"user",
".",
"has_per... | [
490,
4
] | [
503,
74
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.has_view_permission | (self, request, obj=None) |
Return True if the given request has permission to view the given
Django model instance. The default implementation doesn't examine the
`obj` parameter.
If overridden by the user in subclasses, it should return True if the
given request has permission to view the `obj` model in... |
Return True if the given request has permission to view the given
Django model instance. The default implementation doesn't examine the
`obj` parameter. | def has_view_permission(self, request, obj=None):
"""
Return True if the given request has permission to view the given
Django model instance. The default implementation doesn't examine the
`obj` parameter.
If overridden by the user in subclasses, it should return True if the
... | [
"def",
"has_view_permission",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"opts",
"=",
"self",
".",
"opts",
"codename_view",
"=",
"get_permission_codename",
"(",
"'view'",
",",
"opts",
")",
"codename_change",
"=",
"get_permission_codename",
... | [
505,
4
] | [
522,
9
] | python | en | ['en', 'error', 'th'] | False |
BaseModelAdmin.has_module_permission | (self, request) |
Return True if the given request has any permission in the given
app label.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to view the module on
the admin index page and access the module's index page. Overrid... |
Return True if the given request has any permission in the given
app label. | def has_module_permission(self, request):
"""
Return True if the given request has any permission in the given
app label.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to view the module on
the admin i... | [
"def",
"has_module_permission",
"(",
"self",
",",
"request",
")",
":",
"return",
"request",
".",
"user",
".",
"has_module_perms",
"(",
"self",
".",
"opts",
".",
"app_label",
")"
] | [
527,
4
] | [
538,
65
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_model_perms | (self, request) |
Return a dict of all perms for this model. This dict has the keys
``add``, ``change``, ``delete``, and ``view`` mapping to the True/False
for each of those actions.
|
Return a dict of all perms for this model. This dict has the keys
``add``, ``change``, ``delete``, and ``view`` mapping to the True/False
for each of those actions.
| def get_model_perms(self, request):
"""
Return a dict of all perms for this model. This dict has the keys
``add``, ``change``, ``delete``, and ``view`` mapping to the True/False
for each of those actions.
"""
return {
'add': self.has_add_permission(request),
... | [
"def",
"get_model_perms",
"(",
"self",
",",
"request",
")",
":",
"return",
"{",
"'add'",
":",
"self",
".",
"has_add_permission",
"(",
"request",
")",
",",
"'change'",
":",
"self",
".",
"has_change_permission",
"(",
"request",
")",
",",
"'delete'",
":",
"se... | [
644,
4
] | [
655,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_form | (self, request, obj=None, change=False, **kwargs) |
Return a Form class for use in the admin add view. This is used by
add_view and change_view.
|
Return a Form class for use in the admin add view. This is used by
add_view and change_view.
| def get_form(self, request, obj=None, change=False, **kwargs):
"""
Return a Form class for use in the admin add view. This is used by
add_view and change_view.
"""
if 'fields' in kwargs:
fields = kwargs.pop('fields')
else:
fields = flatten_fieldset... | [
"def",
"get_form",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
",",
"change",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'fields'",
"in",
"kwargs",
":",
"fields",
"=",
"kwargs",
".",
"pop",
"(",
"'fields'",
")",
"else",
":",
... | [
660,
4
] | [
706,
13
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_changelist | (self, request, **kwargs) |
Return the ChangeList class for use on the changelist page.
|
Return the ChangeList class for use on the changelist page.
| def get_changelist(self, request, **kwargs):
"""
Return the ChangeList class for use on the changelist page.
"""
from django.contrib.admin.views.main import ChangeList
return ChangeList | [
"def",
"get_changelist",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"django",
".",
"contrib",
".",
"admin",
".",
"views",
".",
"main",
"import",
"ChangeList",
"return",
"ChangeList"
] | [
708,
4
] | [
713,
25
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_changelist_instance | (self, request) |
Return a `ChangeList` instance based on `request`. May raise
`IncorrectLookupParameters`.
|
Return a `ChangeList` instance based on `request`. May raise
`IncorrectLookupParameters`.
| def get_changelist_instance(self, request):
"""
Return a `ChangeList` instance based on `request`. May raise
`IncorrectLookupParameters`.
"""
list_display = self.get_list_display(request)
list_display_links = self.get_list_display_links(request, list_display)
# Ad... | [
"def",
"get_changelist_instance",
"(",
"self",
",",
"request",
")",
":",
"list_display",
"=",
"self",
".",
"get_list_display",
"(",
"request",
")",
"list_display_links",
"=",
"self",
".",
"get_list_display_links",
"(",
"request",
",",
"list_display",
")",
"# Add t... | [
715,
4
] | [
741,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_object | (self, request, object_id, from_field=None) |
Return an instance matching the field and value provided, the primary
key is used if no field is provided. Return ``None`` if no match is
found or the object_id fails validation.
|
Return an instance matching the field and value provided, the primary
key is used if no field is provided. Return ``None`` if no match is
found or the object_id fails validation.
| def get_object(self, request, object_id, from_field=None):
"""
Return an instance matching the field and value provided, the primary
key is used if no field is provided. Return ``None`` if no match is
found or the object_id fails validation.
"""
queryset = self.get_querys... | [
"def",
"get_object",
"(",
"self",
",",
"request",
",",
"object_id",
",",
"from_field",
"=",
"None",
")",
":",
"queryset",
"=",
"self",
".",
"get_queryset",
"(",
"request",
")",
"model",
"=",
"queryset",
".",
"model",
"field",
"=",
"model",
".",
"_meta",
... | [
743,
4
] | [
756,
23
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_changelist_form | (self, request, **kwargs) |
Return a Form class for use in the Formset on the changelist page.
|
Return a Form class for use in the Formset on the changelist page.
| def get_changelist_form(self, request, **kwargs):
"""
Return a Form class for use in the Formset on the changelist page.
"""
defaults = {
'formfield_callback': partial(self.formfield_for_dbfield, request=request),
**kwargs,
}
if defaults.get('field... | [
"def",
"get_changelist_form",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"defaults",
"=",
"{",
"'formfield_callback'",
":",
"partial",
"(",
"self",
".",
"formfield_for_dbfield",
",",
"request",
"=",
"request",
")",
",",
"*",
"*",
"kwar... | [
758,
4
] | [
769,
56
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_changelist_formset | (self, request, **kwargs) |
Return a FormSet class for use on the changelist page if list_editable
is used.
|
Return a FormSet class for use on the changelist page if list_editable
is used.
| def get_changelist_formset(self, request, **kwargs):
"""
Return a FormSet class for use on the changelist page if list_editable
is used.
"""
defaults = {
'formfield_callback': partial(self.formfield_for_dbfield, request=request),
**kwargs,
}
... | [
"def",
"get_changelist_formset",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"defaults",
"=",
"{",
"'formfield_callback'",
":",
"partial",
"(",
"self",
".",
"formfield_for_dbfield",
",",
"request",
"=",
"request",
")",
",",
"*",
"*",
"k... | [
771,
4
] | [
783,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_formsets_with_inlines | (self, request, obj=None) |
Yield formsets and the corresponding inlines.
|
Yield formsets and the corresponding inlines.
| def get_formsets_with_inlines(self, request, obj=None):
"""
Yield formsets and the corresponding inlines.
"""
for inline in self.get_inline_instances(request, obj):
yield inline.get_formset(request, obj), inline | [
"def",
"get_formsets_with_inlines",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"for",
"inline",
"in",
"self",
".",
"get_inline_instances",
"(",
"request",
",",
"obj",
")",
":",
"yield",
"inline",
".",
"get_formset",
"(",
"request",
","... | [
785,
4
] | [
790,
58
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.log_addition | (self, request, object, message) |
Log that an object has been successfully added.
The default implementation creates an admin LogEntry object.
|
Log that an object has been successfully added. | def log_addition(self, request, object, message):
"""
Log that an object has been successfully added.
The default implementation creates an admin LogEntry object.
"""
from django.contrib.admin.models import LogEntry, ADDITION
return LogEntry.objects.log_action(
... | [
"def",
"log_addition",
"(",
"self",
",",
"request",
",",
"object",
",",
"message",
")",
":",
"from",
"django",
".",
"contrib",
".",
"admin",
".",
"models",
"import",
"LogEntry",
",",
"ADDITION",
"return",
"LogEntry",
".",
"objects",
".",
"log_action",
"(",... | [
795,
4
] | [
809,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.log_change | (self, request, object, message) |
Log that an object has been successfully changed.
The default implementation creates an admin LogEntry object.
|
Log that an object has been successfully changed. | def log_change(self, request, object, message):
"""
Log that an object has been successfully changed.
The default implementation creates an admin LogEntry object.
"""
from django.contrib.admin.models import LogEntry, CHANGE
return LogEntry.objects.log_action(
... | [
"def",
"log_change",
"(",
"self",
",",
"request",
",",
"object",
",",
"message",
")",
":",
"from",
"django",
".",
"contrib",
".",
"admin",
".",
"models",
"import",
"LogEntry",
",",
"CHANGE",
"return",
"LogEntry",
".",
"objects",
".",
"log_action",
"(",
"... | [
811,
4
] | [
825,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.log_deletion | (self, request, object, object_repr) |
Log that an object will be deleted. Note that this method must be
called before the deletion.
The default implementation creates an admin LogEntry object.
|
Log that an object will be deleted. Note that this method must be
called before the deletion. | def log_deletion(self, request, object, object_repr):
"""
Log that an object will be deleted. Note that this method must be
called before the deletion.
The default implementation creates an admin LogEntry object.
"""
from django.contrib.admin.models import LogEntry, DELE... | [
"def",
"log_deletion",
"(",
"self",
",",
"request",
",",
"object",
",",
"object_repr",
")",
":",
"from",
"django",
".",
"contrib",
".",
"admin",
".",
"models",
"import",
"LogEntry",
",",
"DELETION",
"return",
"LogEntry",
".",
"objects",
".",
"log_action",
... | [
827,
4
] | [
841,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.action_checkbox | (self, obj) |
A list_display column containing a checkbox widget.
|
A list_display column containing a checkbox widget.
| def action_checkbox(self, obj):
"""
A list_display column containing a checkbox widget.
"""
return helpers.checkbox.render(helpers.ACTION_CHECKBOX_NAME, str(obj.pk)) | [
"def",
"action_checkbox",
"(",
"self",
",",
"obj",
")",
":",
"return",
"helpers",
".",
"checkbox",
".",
"render",
"(",
"helpers",
".",
"ACTION_CHECKBOX_NAME",
",",
"str",
"(",
"obj",
".",
"pk",
")",
")"
] | [
843,
4
] | [
847,
81
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin._get_base_actions | (self) | Return the list of actions, prior to any request-based filtering. | Return the list of actions, prior to any request-based filtering. | def _get_base_actions(self):
"""Return the list of actions, prior to any request-based filtering."""
actions = []
# Gather actions from the admin site first
for (name, func) in self.admin_site.actions:
description = getattr(func, 'short_description', name.replace('_', ' '))
... | [
"def",
"_get_base_actions",
"(",
"self",
")",
":",
"actions",
"=",
"[",
"]",
"# Gather actions from the admin site first",
"for",
"(",
"name",
",",
"func",
")",
"in",
"self",
".",
"admin_site",
".",
"actions",
":",
"description",
"=",
"getattr",
"(",
"func",
... | [
850,
4
] | [
861,
36
] | python | en | ['en', 'en', 'en'] | True |
ModelAdmin._filter_actions_by_permissions | (self, request, actions) | Filter out any actions that the user doesn't have access to. | Filter out any actions that the user doesn't have access to. | def _filter_actions_by_permissions(self, request, actions):
"""Filter out any actions that the user doesn't have access to."""
filtered_actions = []
for action in actions:
callable = action[0]
if not hasattr(callable, 'allowed_permissions'):
filtered_actio... | [
"def",
"_filter_actions_by_permissions",
"(",
"self",
",",
"request",
",",
"actions",
")",
":",
"filtered_actions",
"=",
"[",
"]",
"for",
"action",
"in",
"actions",
":",
"callable",
"=",
"action",
"[",
"0",
"]",
"if",
"not",
"hasattr",
"(",
"callable",
","... | [
863,
4
] | [
877,
31
] | python | en | ['en', 'en', 'en'] | True |
ModelAdmin.get_actions | (self, request) |
Return a dictionary mapping the names of all actions for this
ModelAdmin to a tuple of (callable, name, description) for each action.
|
Return a dictionary mapping the names of all actions for this
ModelAdmin to a tuple of (callable, name, description) for each action.
| def get_actions(self, request):
"""
Return a dictionary mapping the names of all actions for this
ModelAdmin to a tuple of (callable, name, description) for each action.
"""
# If self.actions is set to None that means actions are disabled on
# this page.
if self.a... | [
"def",
"get_actions",
"(",
"self",
",",
"request",
")",
":",
"# If self.actions is set to None that means actions are disabled on",
"# this page.",
"if",
"self",
".",
"actions",
"is",
"None",
"or",
"IS_POPUP_VAR",
"in",
"request",
".",
"GET",
":",
"return",
"{",
"}"... | [
879,
4
] | [
889,
73
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_action_choices | (self, request, default_choices=BLANK_CHOICE_DASH) |
Return a list of choices for use in a form object. Each choice is a
tuple (name, description).
|
Return a list of choices for use in a form object. Each choice is a
tuple (name, description).
| def get_action_choices(self, request, default_choices=BLANK_CHOICE_DASH):
"""
Return a list of choices for use in a form object. Each choice is a
tuple (name, description).
"""
choices = [] + default_choices
for func, name, description in self.get_actions(request).values... | [
"def",
"get_action_choices",
"(",
"self",
",",
"request",
",",
"default_choices",
"=",
"BLANK_CHOICE_DASH",
")",
":",
"choices",
"=",
"[",
"]",
"+",
"default_choices",
"for",
"func",
",",
"name",
",",
"description",
"in",
"self",
".",
"get_actions",
"(",
"re... | [
891,
4
] | [
900,
22
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_action | (self, action) |
Return a given action from a parameter, which can either be a callable,
or the name of a method on the ModelAdmin. Return is a tuple of
(callable, name, description).
|
Return a given action from a parameter, which can either be a callable,
or the name of a method on the ModelAdmin. Return is a tuple of
(callable, name, description).
| def get_action(self, action):
"""
Return a given action from a parameter, which can either be a callable,
or the name of a method on the ModelAdmin. Return is a tuple of
(callable, name, description).
"""
# If the action is a callable, just use it.
if callable(ac... | [
"def",
"get_action",
"(",
"self",
",",
"action",
")",
":",
"# If the action is a callable, just use it.",
"if",
"callable",
"(",
"action",
")",
":",
"func",
"=",
"action",
"action",
"=",
"action",
".",
"__name__",
"# Next, look for a method. Grab it off self.__class__ t... | [
902,
4
] | [
930,
40
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_list_display | (self, request) |
Return a sequence containing the fields to be displayed on the
changelist.
|
Return a sequence containing the fields to be displayed on the
changelist.
| def get_list_display(self, request):
"""
Return a sequence containing the fields to be displayed on the
changelist.
"""
return self.list_display | [
"def",
"get_list_display",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"list_display"
] | [
932,
4
] | [
937,
32
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_list_display_links | (self, request, list_display) |
Return a sequence containing the fields to be displayed as links
on the changelist. The list_display parameter is the list of fields
returned by get_list_display().
|
Return a sequence containing the fields to be displayed as links
on the changelist. The list_display parameter is the list of fields
returned by get_list_display().
| def get_list_display_links(self, request, list_display):
"""
Return a sequence containing the fields to be displayed as links
on the changelist. The list_display parameter is the list of fields
returned by get_list_display().
"""
if self.list_display_links or self.list_di... | [
"def",
"get_list_display_links",
"(",
"self",
",",
"request",
",",
"list_display",
")",
":",
"if",
"self",
".",
"list_display_links",
"or",
"self",
".",
"list_display_links",
"is",
"None",
"or",
"not",
"list_display",
":",
"return",
"self",
".",
"list_display_li... | [
939,
4
] | [
949,
41
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_list_filter | (self, request) |
Return a sequence containing the fields to be displayed as filters in
the right sidebar of the changelist page.
|
Return a sequence containing the fields to be displayed as filters in
the right sidebar of the changelist page.
| def get_list_filter(self, request):
"""
Return a sequence containing the fields to be displayed as filters in
the right sidebar of the changelist page.
"""
return self.list_filter | [
"def",
"get_list_filter",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"list_filter"
] | [
951,
4
] | [
956,
31
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_list_select_related | (self, request) |
Return a list of fields to add to the select_related() part of the
changelist items query.
|
Return a list of fields to add to the select_related() part of the
changelist items query.
| def get_list_select_related(self, request):
"""
Return a list of fields to add to the select_related() part of the
changelist items query.
"""
return self.list_select_related | [
"def",
"get_list_select_related",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"list_select_related"
] | [
958,
4
] | [
963,
39
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_search_fields | (self, request) |
Return a sequence containing the fields to be searched whenever
somebody submits a search query.
|
Return a sequence containing the fields to be searched whenever
somebody submits a search query.
| def get_search_fields(self, request):
"""
Return a sequence containing the fields to be searched whenever
somebody submits a search query.
"""
return self.search_fields | [
"def",
"get_search_fields",
"(",
"self",
",",
"request",
")",
":",
"return",
"self",
".",
"search_fields"
] | [
965,
4
] | [
970,
33
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_search_results | (self, request, queryset, search_term) |
Return a tuple containing a queryset to implement the search
and a boolean indicating if the results may contain duplicates.
|
Return a tuple containing a queryset to implement the search
and a boolean indicating if the results may contain duplicates.
| def get_search_results(self, request, queryset, search_term):
"""
Return a tuple containing a queryset to implement the search
and a boolean indicating if the results may contain duplicates.
"""
# Apply keyword searches.
def construct_search(field_name):
if fi... | [
"def",
"get_search_results",
"(",
"self",
",",
"request",
",",
"queryset",
",",
"search_term",
")",
":",
"# Apply keyword searches.",
"def",
"construct_search",
"(",
"field_name",
")",
":",
"if",
"field_name",
".",
"startswith",
"(",
"'^'",
")",
":",
"return",
... | [
972,
4
] | [
1018,
37
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.get_preserved_filters | (self, request) |
Return the preserved filters querystring.
|
Return the preserved filters querystring.
| def get_preserved_filters(self, request):
"""
Return the preserved filters querystring.
"""
match = request.resolver_match
if self.preserve_filters and match:
opts = self.model._meta
current_url = '%s:%s' % (match.app_name, match.url_name)
chan... | [
"def",
"get_preserved_filters",
"(",
"self",
",",
"request",
")",
":",
"match",
"=",
"request",
".",
"resolver_match",
"if",
"self",
".",
"preserve_filters",
"and",
"match",
":",
"opts",
"=",
"self",
".",
"model",
".",
"_meta",
"current_url",
"=",
"'%s:%s'",... | [
1020,
4
] | [
1036,
17
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.construct_change_message | (self, request, form, formsets, add=False) |
Construct a JSON structure describing changes from a changed object.
|
Construct a JSON structure describing changes from a changed object.
| def construct_change_message(self, request, form, formsets, add=False):
"""
Construct a JSON structure describing changes from a changed object.
"""
return construct_change_message(form, formsets, add) | [
"def",
"construct_change_message",
"(",
"self",
",",
"request",
",",
"form",
",",
"formsets",
",",
"add",
"=",
"False",
")",
":",
"return",
"construct_change_message",
"(",
"form",
",",
"formsets",
",",
"add",
")"
] | [
1038,
4
] | [
1042,
60
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.message_user | (self, request, message, level=messages.INFO, extra_tags='',
fail_silently=False) |
Send a message to the user. The default implementation
posts a message using the django.contrib.messages backend.
Exposes almost the same API as messages.add_message(), but accepts the
positional arguments in a different order to maintain backwards
compatibility. For convenienc... |
Send a message to the user. The default implementation
posts a message using the django.contrib.messages backend. | def message_user(self, request, message, level=messages.INFO, extra_tags='',
fail_silently=False):
"""
Send a message to the user. The default implementation
posts a message using the django.contrib.messages backend.
Exposes almost the same API as messages.add_messa... | [
"def",
"message_user",
"(",
"self",
",",
"request",
",",
"message",
",",
"level",
"=",
"messages",
".",
"INFO",
",",
"extra_tags",
"=",
"''",
",",
"fail_silently",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"level",
",",
"int",
")",
":",
... | [
1044,
4
] | [
1067,
105
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.save_form | (self, request, form, change) |
Given a ModelForm return an unsaved instance. ``change`` is True if
the object is being changed, and False if it's being added.
|
Given a ModelForm return an unsaved instance. ``change`` is True if
the object is being changed, and False if it's being added.
| def save_form(self, request, form, change):
"""
Given a ModelForm return an unsaved instance. ``change`` is True if
the object is being changed, and False if it's being added.
"""
return form.save(commit=False) | [
"def",
"save_form",
"(",
"self",
",",
"request",
",",
"form",
",",
"change",
")",
":",
"return",
"form",
".",
"save",
"(",
"commit",
"=",
"False",
")"
] | [
1069,
4
] | [
1074,
38
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.save_model | (self, request, obj, form, change) |
Given a model instance save it to the database.
|
Given a model instance save it to the database.
| def save_model(self, request, obj, form, change):
"""
Given a model instance save it to the database.
"""
obj.save() | [
"def",
"save_model",
"(",
"self",
",",
"request",
",",
"obj",
",",
"form",
",",
"change",
")",
":",
"obj",
".",
"save",
"(",
")"
] | [
1076,
4
] | [
1080,
18
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.delete_model | (self, request, obj) |
Given a model instance delete it from the database.
|
Given a model instance delete it from the database.
| def delete_model(self, request, obj):
"""
Given a model instance delete it from the database.
"""
obj.delete() | [
"def",
"delete_model",
"(",
"self",
",",
"request",
",",
"obj",
")",
":",
"obj",
".",
"delete",
"(",
")"
] | [
1082,
4
] | [
1086,
20
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.delete_queryset | (self, request, queryset) | Given a queryset, delete it from the database. | Given a queryset, delete it from the database. | def delete_queryset(self, request, queryset):
"""Given a queryset, delete it from the database."""
queryset.delete() | [
"def",
"delete_queryset",
"(",
"self",
",",
"request",
",",
"queryset",
")",
":",
"queryset",
".",
"delete",
"(",
")"
] | [
1088,
4
] | [
1090,
25
] | python | en | ['en', 'en', 'en'] | True |
ModelAdmin.save_formset | (self, request, form, formset, change) |
Given an inline formset save it to the database.
|
Given an inline formset save it to the database.
| def save_formset(self, request, form, formset, change):
"""
Given an inline formset save it to the database.
"""
formset.save() | [
"def",
"save_formset",
"(",
"self",
",",
"request",
",",
"form",
",",
"formset",
",",
"change",
")",
":",
"formset",
".",
"save",
"(",
")"
] | [
1092,
4
] | [
1096,
22
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.save_related | (self, request, form, formsets, change) |
Given the ``HttpRequest``, the parent ``ModelForm`` instance, the
list of inline formsets and a boolean value based on whether the
parent is being added or changed, save the related objects to the
database. Note that at this point save_form() and save_model() have
already been c... |
Given the ``HttpRequest``, the parent ``ModelForm`` instance, the
list of inline formsets and a boolean value based on whether the
parent is being added or changed, save the related objects to the
database. Note that at this point save_form() and save_model() have
already been c... | def save_related(self, request, form, formsets, change):
"""
Given the ``HttpRequest``, the parent ``ModelForm`` instance, the
list of inline formsets and a boolean value based on whether the
parent is being added or changed, save the related objects to the
database. Note that at... | [
"def",
"save_related",
"(",
"self",
",",
"request",
",",
"form",
",",
"formsets",
",",
"change",
")",
":",
"form",
".",
"save_m2m",
"(",
")",
"for",
"formset",
"in",
"formsets",
":",
"self",
".",
"save_formset",
"(",
"request",
",",
"form",
",",
"forms... | [
1098,
4
] | [
1108,
68
] | python | en | ['en', 'error', 'th'] | False |
ModelAdmin.response_add | (self, request, obj, post_url_continue=None) |
Determine the HttpResponse for the add_view stage.
|
Determine the HttpResponse for the add_view stage.
| def response_add(self, request, obj, post_url_continue=None):
"""
Determine the HttpResponse for the add_view stage.
"""
opts = obj._meta
preserved_filters = self.get_preserved_filters(request)
obj_url = reverse(
'admin:%s_%s_change' % (opts.app_label, opts.mo... | [
"def",
"response_add",
"(",
"self",
",",
"request",
",",
"obj",
",",
"post_url_continue",
"=",
"None",
")",
":",
"opts",
"=",
"obj",
".",
"_meta",
"preserved_filters",
"=",
"self",
".",
"get_preserved_filters",
"(",
"request",
")",
"obj_url",
"=",
"reverse",... | [
1157,
4
] | [
1232,
60
] | 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.