Skip to content

Commit

Permalink
add opts enable_foreign_link
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnb14 committed Oct 12, 2023
1 parent 25e7379 commit 70793ef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ Enhance UI/UX of django admin
- Read only mode
- Bookmark menu
- Ignore confirm delete page option
- Add link for foregin key in change list page
- And more utils functions


Install
=======

Expand Down Expand Up @@ -95,6 +97,7 @@ Basic Usage
- **super_admin_only_fields** (list, default []) Only show these fields if user login is superuser
- **ext_read_only_fields** (list, default []) Only show these fields in view mode. Default custom fields start with `display_` was mark as read only so you don't need add these fields to ext_read_only_fields
- **ext_write_only_fields** (list, default []) Only show these fields in edit mode
- **enable_foreign_link** (boolean, default True) Add link for foregin key in change list page


Advand
Expand Down
5 changes: 3 additions & 2 deletions admin_extended/base/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def changelist_view(self, request, extra_context=None):


class DispayLinkAdapter:
enable_foreign_link = True

def _foreign_key_link(self, field_name, description):
"""
Expand Down Expand Up @@ -157,12 +158,12 @@ def convert_display_fields(self, list_display):
}

if field.__class__.__name__ == 'ForeignKey':
field_mapping[field.attname[:-3]] = field_mapping[field.attname] # Eg `user_id` -> `user` key have same info
field_mapping[field.attname[:-3]] = field_mapping[field.attname] # Eg make `user_id` -> `user` key have same info

results = [list_display[0]]
for field_name in list_display[1:]: # ignore first field
field_info = field_mapping.get(field_name)
if field_info and field_info['class_name'] == 'ForeignKey':
if field_info and field_info['class_name'] == 'ForeignKey' and self.enable_foreign_link:
results.append(self._foreign_key_link(field_name, field_info['verbose_name']))
else:
results.append(field_name)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='django-admin-extended',
version='3.2',
version='3.2.1',
packages=find_packages(),
include_package_data=True,
license='MIT License',
Expand Down

0 comments on commit 70793ef

Please sign in to comment.