Skip to content

Commit 75370a9

Browse files
authored
Merge pull request #41 from escaped/fix/get_fields
ModelAdminMixin: Only remove 'render_inline_actions' if exists
2 parents 959465a + 228c5c2 commit 75370a9

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
* Do not break if `render_inline_actions` field is missing, thanks to @tony
13+
1014
### Added
1115

1216
* support for django 3.x

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
- [@nikbora](https://github.com/nikbora)
77
- [@orwald-sergesson](https://github.com/torwald-sergesson)
88
- [@sobolevn](https://github.com/sobolevn)
9+
- [@tony](https://github.com/tony)
910
- [@tripliks](https://github.com/tripliks)

inline_actions/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def get_fields(self, request, obj=None):
176176
# django adds all readonly fields by default
177177
# if `self.fields` is not defined we don't want to include
178178
# `render_inline_actions
179-
fields.remove('render_inline_actions')
179+
if 'render_inline_actions' in fields:
180+
fields.remove('render_inline_actions')
180181
return fields
181182

182183
def _execute_action(self, request, model_admin, action, obj, parent_obj=None):

test_proj/blog/tests/test_admin.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,32 @@ def test_skip_rendering_actions_for_unsaved_objects(admin_client, mocker, articl
216216
admin = ArticleAdmin(unsaved_article, admin_site)
217217

218218
assert admin.render_inline_actions(unsaved_article) == ''
219+
220+
221+
@pytest.mark.django_db
222+
def test_missing_render_inline_actions_from_readonly_fields(
223+
rf, admin_user, admin_site, article
224+
):
225+
"""
226+
Make sure that customization does not break the app.
227+
"""
228+
from test_proj.blog import admin
229+
230+
class ArticleAdmin(admin.InlineActionsModelAdminMixin, admin.admin.ModelAdmin):
231+
list_display = ('name',)
232+
inline_actions = None
233+
234+
def get_readonly_fields(self, *args, **kwargs):
235+
"""
236+
Do some fancy logic to return a list of fields, which does not include `render_inline_actions`.
237+
"""
238+
return []
239+
240+
request = rf.get(f'/admin/blog/articles/{article.id}/')
241+
request.user = admin_user
242+
243+
admin = ArticleAdmin(Article, admin_site)
244+
245+
# even though `render_inline_actions` is not part of the fields,
246+
# it should not fail :)
247+
admin.changeform_view(request)

0 commit comments

Comments
 (0)