New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #6327 -- Added has_module_permission method to BaseModelAdmin #2730
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -1631,6 +1631,19 @@ templates used by the :class:`ModelAdmin` views: | ||
be interpreted as meaning that the current user is not permitted to delete | be interpreted as meaning that the current user is not permitted to delete | ||
any object of this type). | any object of this type). | ||
|
|
||
.. method:: ModelAdmin.has_module_permission(request) | |||
|
|||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .. versionadded:: 1.8 and add a mention in the 1.8 release notes |
|||
.. versionadded:: 1.8 | |||
|
|||
Should return ``True`` if adding, editing, or deleting an object is | |||
permitted, ``False`` otherwise. Uses :meth:`User.has_module_perms() | |||
<django.contrib.auth.models.User.has_module_perms>` by default. It is | |||
used for displaying the module on the admin index page and for accessing | |||
the module's index page. Overriding it does not restrict access to the add, | |||
change or delete views, :meth:`~ModelAdmin.has_add_permission`, | |||
:meth:`~ModelAdmin.has_change_permission`, or | |||
:meth:`~ModelAdmin.has_delete_permission` should be used for that. | |||
|
|||
.. method:: ModelAdmin.get_queryset(request) | .. method:: ModelAdmin.get_queryset(request) | ||
|
|
||
The ``get_queryset`` method on a ``ModelAdmin`` returns a | The ``get_queryset`` method on a ``ModelAdmin`` returns a | ||
|
@@ -1909,6 +1922,7 @@ adds some of its own (the shared features are actually defined in the | ||
- :meth:`~ModelAdmin.has_add_permission` | - :meth:`~ModelAdmin.has_add_permission` | ||
- :meth:`~ModelAdmin.has_change_permission` | - :meth:`~ModelAdmin.has_change_permission` | ||
- :meth:`~ModelAdmin.has_delete_permission` | - :meth:`~ModelAdmin.has_delete_permission` | ||
- :meth:`~ModelAdmin.has_module_permission` | |||
|
|
||
The ``InlineModelAdmin`` class adds: | The ``InlineModelAdmin`` class adds: | ||
|
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method needs to be used by the ModelAdmin... (and should add a test that overriding it achieves the desired functionality)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand where to use this method in ModelAdmin. Should I replace occurrences of user.has_module_perms by model_admin.has_module_permission (like in the index() and app_index() methods of AdminSite) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe that's the point of the suggestion -- so you can override the method if you want to customize the behavior.