Skip to content
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

Fix BaseModelAdmin.view_on_site annotation #1993

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class BaseModelAdmin(Generic[_ModelT]):
readonly_fields: _ListOrTuple[str]
ordering: _ListOrTuple[str] | None
sortable_by: _ListOrTuple[str] | None
view_on_site: bool | Callable[[_ModelT], str]
show_full_result_count: bool
checks_class: Any
model: type[_ModelT]
Expand Down Expand Up @@ -136,6 +135,8 @@ class BaseModelAdmin(Generic[_ModelT]):
def has_view_permission(self, request: HttpRequest, obj: _ModelT | None = ...) -> bool: ...
def has_view_or_change_permission(self, request: HttpRequest, obj: _ModelT | None = ...) -> bool: ...
def has_module_permission(self, request: HttpRequest) -> bool: ...
@property
def view_on_site(self) -> Callable[[_ModelT], str] | bool: ...

_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin)
_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], HttpResponseBase | None]
Expand Down
7 changes: 7 additions & 0 deletions tests/typecheck/contrib/admin/test_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
'fields': ('name',),
}),
)
- case: test_view_on_site_as_callable
main: |
from django.contrib import admin
class A(admin.ModelAdmin):
def view_on_site(self, obj: "A") -> str:
return "http://example.org"
- case: errors_on_omitting_fields_from_fieldset_opts
main: |
from django.contrib import admin
Expand Down