mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 05:51:53 +08:00
make BaseModelAdmin generic to properly type methods dealing with models (#504)
* make BaseModelAdmin generic to properly type the `obj` argument of ModelAdmin.delete_model closes #482 * turn BaseModelAdmin into bound generic, run black * add test for generic ModelAdmin
This commit is contained in:
@@ -14,7 +14,10 @@
|
||||
def an_action(modeladmin: admin.ModelAdmin, request: HttpRequest, queryset: QuerySet) -> None:
|
||||
pass
|
||||
|
||||
class A(admin.ModelAdmin):
|
||||
class TestModel(models.Model):
|
||||
pass
|
||||
|
||||
class A(admin.ModelAdmin[TestModel]):
|
||||
# BaseModelAdmin
|
||||
autocomplete_fields = ("strs",)
|
||||
raw_id_fields = ["strs"]
|
||||
@@ -71,6 +74,11 @@
|
||||
actions_selection_counter = True
|
||||
admin_site = AdminSite()
|
||||
|
||||
# test generic ModelAdmin
|
||||
# https://github.com/typeddjango/django-stubs/pull/504
|
||||
# this will fail if `model` has a type other than the generic specified in the class declaration
|
||||
model = TestModel
|
||||
|
||||
def a_method_action(self, request, queryset):
|
||||
pass
|
||||
|
||||
@@ -127,4 +135,4 @@
|
||||
pass
|
||||
|
||||
class A(admin.ModelAdmin):
|
||||
actions = [an_action] # E: List item 0 has incompatible type "Callable[[None], None]"; expected "Union[Callable[[ModelAdmin, HttpRequest, QuerySet[Any]], None], str]"
|
||||
actions = [an_action] # E: List item 0 has incompatible type "Callable[[None], None]"; expected "Union[Callable[[ModelAdmin[Any], HttpRequest, QuerySet[Any]], None], str]"
|
||||
|
||||
Reference in New Issue
Block a user