-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
get_context_object_name
on SingleObjectMixin
and `Multipl…
…eObjectMixin` (#2298)
- Loading branch information
Showing
4 changed files
with
48 additions
and
7 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from typing import Optional, Type | ||
|
||
from django.db import models | ||
from django.views.generic.detail import SingleObjectMixin | ||
from django.views.generic.list import ListView | ||
from typing_extensions import assert_type | ||
|
||
|
||
class MyModel(models.Model): ... | ||
|
||
|
||
class MyDetailView(SingleObjectMixin[MyModel]): ... | ||
|
||
|
||
detail_view = MyDetailView() | ||
assert_type(detail_view.model, Type[MyModel]) | ||
assert_type(detail_view.queryset, Optional[models.QuerySet[MyModel, MyModel]]) | ||
assert_type(detail_view.get_context_object_name(MyModel()), str) | ||
assert_type(detail_view.get_context_object_name(1), Optional[str]) | ||
|
||
|
||
class MyListView(ListView[MyModel]): ... | ||
|
||
|
||
list_view = MyListView() | ||
assert_type(list_view.model, Optional[Type[MyModel]]) | ||
assert_type(list_view.queryset, Optional[models.QuerySet[MyModel, MyModel]]) | ||
assert_type(list_view.get_context_object_name(models.QuerySet[MyModel]()), str) | ||
assert_type(list_view.get_context_object_name(MyModel()), Optional[str]) | ||
assert_type(list_view.get_context_object_name(1), Optional[str]) |
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