-
-
Notifications
You must be signed in to change notification settings - Fork 450
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
Constrain multiple BaseModelAdmin
attributes to be either list or tuple
#1832
Merged
sobolevn
merged 1 commit into
typeddjango:master
from
flaeppe:fix/admin-list-or-tuple-checks
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,19 +76,19 @@ _ListFilterT: TypeAlias = ( | |
_ModelT = TypeVar("_ModelT", bound=Model) | ||
|
||
class BaseModelAdmin(Generic[_ModelT]): | ||
autocomplete_fields: Sequence[str] | ||
raw_id_fields: Sequence[str] | ||
autocomplete_fields: _ListOrTuple[str] | ||
raw_id_fields: _ListOrTuple[str] | ||
fields: _FieldGroups | None | ||
exclude: Sequence[str] | None | ||
exclude: _ListOrTuple[str] | None | ||
fieldsets: _FieldsetSpec | None | ||
form: type[forms.ModelForm[_ModelT]] | ||
filter_vertical: Sequence[str] | ||
filter_horizontal: Sequence[str] | ||
filter_vertical: _ListOrTuple[str] | ||
filter_horizontal: _ListOrTuple[str] | ||
radio_fields: Mapping[str, _Direction] | ||
prepopulated_fields: dict[str, Sequence[str]] | ||
formfield_overrides: Mapping[type[Field], Mapping[str, Any]] | ||
readonly_fields: Sequence[str] | ||
ordering: Sequence[str] | None | ||
readonly_fields: _ListOrTuple[str] | None | ||
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. I don't think 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. Oh, nice find. This was a copy paste mistake.. |
||
ordering: _ListOrTuple[str] | None | ||
sortable_by: _ListOrTuple[str] | None | ||
view_on_site: bool | Callable[[_ModelT], str] | ||
show_full_result_count: bool | ||
|
@@ -136,19 +136,19 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): | |
list_display: _DisplayT | ||
list_display_links: _DisplayT | None | ||
list_filter: _ListOrTuple[_ListFilterT] | ||
list_select_related: bool | Sequence[str] | ||
list_select_related: bool | _ListOrTuple[str] | ||
list_per_page: int | ||
list_max_show_all: int | ||
list_editable: Sequence[str] | ||
search_fields: Sequence[str] | ||
list_editable: _ListOrTuple[str] | ||
search_fields: _ListOrTuple[str] | ||
search_help_text: _StrOrPromise | None | ||
date_hierarchy: str | None | ||
save_as: bool | ||
save_as_continue: bool | ||
save_on_top: bool | ||
paginator: type | ||
preserve_filters: bool | ||
inlines: Sequence[type[InlineModelAdmin]] | ||
inlines: _ListOrTuple[type[InlineModelAdmin]] | ||
add_form_template: _TemplateForResponseT | None | ||
change_form_template: _TemplateForResponseT | None | ||
change_list_template: _TemplateForResponseT | None | ||
|
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.
Should we update the getter methods below as well, e.g.
get_exclude(...) -> Sequence[str]
to_ListOrTuple
?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.
Hm, I'm not totally sure but it could probably be reasonable to align? I mean, per default these methods just do
return self.<attribute>
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.
Yeah my preference would be to update methods as well.
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.
Yeah, I'll push a new PR with fixes very soon. Trying to check their alignment just now.
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.
See #1833