Tweaks
This commit is contained in:
6987
media/introduction.excalidraw
Normal file
6987
media/introduction.excalidraw
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, Iterator
|
||||
|
||||
from django.db.models import Count, Q
|
||||
|
||||
@ -6,18 +6,19 @@ from project.main.models import CatBreed
|
||||
from project.main.views.demo_view_base import DemoViewBase
|
||||
|
||||
|
||||
def get_countries() -> list[str]:
|
||||
def get_countries() -> Iterator[str]:
|
||||
ann = (
|
||||
CatBreed.objects.values("country")
|
||||
.annotate(Count("country"))
|
||||
.order_by("country")
|
||||
)
|
||||
return [a["country"] for a in ann]
|
||||
for a in ann:
|
||||
yield a["country"]
|
||||
|
||||
|
||||
def filter_cat_breeds(
|
||||
breed_filter: Optional[str] = None, country_filter: Optional[str] = None
|
||||
) -> list[CatBreed]:
|
||||
) -> Iterator[CatBreed]:
|
||||
q = Q()
|
||||
|
||||
if breed_filter:
|
||||
@ -25,7 +26,8 @@ def filter_cat_breeds(
|
||||
if country_filter:
|
||||
q &= Q(country=country_filter)
|
||||
|
||||
return CatBreed.objects.filter(q).order_by("name")
|
||||
for c in CatBreed.objects.filter(q).order_by("name"):
|
||||
yield c
|
||||
|
||||
|
||||
class FilterListView(DemoViewBase):
|
||||
|
||||
Reference in New Issue
Block a user