Skip to content

Commit

Permalink
Fix BaseModelAdmin.view_on_site annotation (#1993)
Browse files Browse the repository at this point in the history
Fixes: #1755
  • Loading branch information
cuu508 authored Mar 7, 2024
1 parent a5af3ef commit cfb6efc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit cfb6efc

Please sign in to comment.