Skip to content

Commit abb3ab0

Browse files
committed
Add type for fieldsets in modeladmin subclass
1 parent 07a8f6b commit abb3ab0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

polls/admin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, Dict, List, Optional, Tuple
2+
13
from django.contrib import admin # type: ignore
24

35
from .models import Question, Choice
@@ -7,12 +9,16 @@ class ChoiceInline(admin.TabularInline):
79
model = Choice
810
extra = 3
911

12+
Title = Optional[str]
13+
Options = Dict[str, Any]
14+
FieldSet = Tuple[Title, Options]
15+
FieldSets = List[FieldSet]
1016

1117
class QuestionAdmin(admin.ModelAdmin):
1218
fieldsets = [
1319
(None, {'fields': ['question_text']}),
1420
('Date information', {'fields': ['pub_date']}),
15-
]
21+
] # type: FieldSets
1622
inlines = [ChoiceInline]
1723
list_display = ('question_text', 'pub_date', 'was_published_recently')
1824
list_filter = ['pub_date']

polls/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def get_queryset(self) -> QuerySet:
2222
pub_date__lte=timezone.now()
2323
).order_by('-pub_date')[:5]
2424

25+
2526
class DetailView(generic.DetailView):
2627
model = Question
2728
template_name = 'polls/detail.html'

0 commit comments

Comments
 (0)