diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index f08f4fcac..a9be3de1f 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -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] @@ -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] diff --git a/tests/typecheck/contrib/admin/test_options.yml b/tests/typecheck/contrib/admin/test_options.yml index 2a640209e..6624a975a 100644 --- a/tests/typecheck/contrib/admin/test_options.yml +++ b/tests/typecheck/contrib/admin/test_options.yml @@ -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