mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
Fixed #15185 -- Allowed ModelAdmin.list_display_links=None to disable change list links.
Thanks rm_ for the suggestion.
This commit is contained in:
committed by
Tim Graham
parent
bf757a2f4d
commit
1d0fc61b1c
@@ -794,7 +794,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
on the changelist. The list_display parameter is the list of fields
|
||||
returned by get_list_display().
|
||||
"""
|
||||
if self.list_display_links or not list_display:
|
||||
if self.list_display_links or self.list_display_links is None or not list_display:
|
||||
return self.list_display_links
|
||||
else:
|
||||
# Use only the first item in list_display as link
|
||||
|
||||
@@ -178,6 +178,14 @@ def items_for_result(cl, result, form):
|
||||
"""
|
||||
Generates the actual list of data.
|
||||
"""
|
||||
|
||||
def link_in_col(is_first, field_name, cl):
|
||||
if cl.list_display_links is None:
|
||||
return False
|
||||
if is_first and not cl.list_display_links:
|
||||
return True
|
||||
return field_name in cl.list_display_links
|
||||
|
||||
first = True
|
||||
pk = cl.lookup_opts.pk.attname
|
||||
for field_name in cl.list_display:
|
||||
@@ -216,7 +224,7 @@ def items_for_result(cl, result, form):
|
||||
result_repr = mark_safe(' ')
|
||||
row_class = mark_safe(' class="%s"' % ' '.join(row_classes))
|
||||
# If list_display_links not defined, add the link tag to the first field
|
||||
if (first and not cl.list_display_links) or field_name in cl.list_display_links:
|
||||
if link_in_col(first, field_name, cl):
|
||||
table_tag = 'th' if first else 'td'
|
||||
first = False
|
||||
|
||||
|
||||
@@ -257,8 +257,10 @@ class ModelAdminValidator(BaseValidator):
|
||||
% (cls.__name__, idx, field))
|
||||
|
||||
def validate_list_display_links(self, cls, model):
|
||||
" Validate that list_display_links is a unique subset of list_display. "
|
||||
" Validate that list_display_links either is None or a unique subset of list_display."
|
||||
if hasattr(cls, 'list_display_links'):
|
||||
if cls.list_display_links is None:
|
||||
return
|
||||
check_isseq(cls, 'list_display_links', cls.list_display_links)
|
||||
for idx, field in enumerate(cls.list_display_links):
|
||||
if field not in cls.list_display:
|
||||
@@ -344,15 +346,16 @@ class ModelAdminValidator(BaseValidator):
|
||||
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to "
|
||||
"'%s' which is not defined in 'list_display'."
|
||||
% (cls.__name__, idx, field_name))
|
||||
if field_name in cls.list_display_links:
|
||||
raise ImproperlyConfigured("'%s' cannot be in both '%s.list_editable'"
|
||||
" and '%s.list_display_links'"
|
||||
% (field_name, cls.__name__, cls.__name__))
|
||||
if not cls.list_display_links and cls.list_display[0] in cls.list_editable:
|
||||
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to"
|
||||
" the first field in list_display, '%s', which can't be"
|
||||
" used unless list_display_links is set."
|
||||
% (cls.__name__, idx, cls.list_display[0]))
|
||||
if cls.list_display_links is not None:
|
||||
if field_name in cls.list_display_links:
|
||||
raise ImproperlyConfigured("'%s' cannot be in both '%s.list_editable'"
|
||||
" and '%s.list_display_links'"
|
||||
% (field_name, cls.__name__, cls.__name__))
|
||||
if not cls.list_display_links and cls.list_display[0] in cls.list_editable:
|
||||
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to"
|
||||
" the first field in list_display, '%s', which can't be"
|
||||
" used unless list_display_links is set."
|
||||
% (cls.__name__, idx, cls.list_display[0]))
|
||||
if not field.editable:
|
||||
raise ImproperlyConfigured("'%s.list_editable[%d]' refers to a "
|
||||
"field, '%s', which isn't editable through the admin."
|
||||
|
||||
Reference in New Issue
Block a user