from typing import TYPE_CHECKING, List
def get_cat_list() -> List["Cat"]
from animals import Cat
return [Cat() for _ in range(3)]
if TYPE_CHECKING:
from animals import Cat
.container {
display: inline-block;
}
Goods.objects.annotate(
PriceGroups_id_1_price = Subquery(Price.objects.filter(goods_id=OuterRef('id'), pricegroup_id=1).values('price')[:1]),
PriceGroups_id_2_price = Subquery(Price.objects.filter(goods_id=OuterRef('id'), pricegroup_id=2).values('price')[:1]),
PriceGroups_id_3_price = Subquery(Price.objects.filter(goods_id=OuterRef('id'), pricegroup_id=3).values('price')[:1]),
)
group_count = 3
subquery = Subquery(Price.objects.filter(goods_id=OuterRef('id')))
qs = Goods.objects.annotate(
**{
f'PriceGroups_id_{group_id}_price': subquery.filter(pricegroup_id=group_id).values(
'price')[:1]
for group_id in range(1, group_count + 1)
}
)
def changelist_view(self, request, extra_context=None):
return HttpResponseRedirect(url_страницы_редактирования_единственной_сущности)
spisok = []
def 1_step(message):
global spisok
spisok.append(...)
# ... Где-то здесь определяем quryset как нефильтрованный набор
title = request.GET.get('title')
price_min = request.GET.get('price_min')
price_max = request.GET.get('price_max')
if title:
quryset = quryset.filter(title=title)
if price_min and price_max:
quryset = quryset.filter(price__range=(price_min, price_max))
elif price_min:
quryset = quryset.filter(price__gte=price_min)
elif price_max:
quryset = quryset.filter(price__lt=price_max)
quryset =
def get_queryset(self):
if not self.request.GET:
return Posts.objects.all()#если нет параметров, просто возвращаем все посты
keyword = self.request.GET.get('key')#получаем ключевое слово
filters = Q()#создаем первый объект Q, что бы складывать с ним другие
for key in ['author', 'name', 'text']:
value = self.request.GET.get(key)
if value:
filters |= Q(**{f'{key}__icontains': keyword})
return Posts.objects.filter(filters)
import json
# ... тут помещаем нашу строку в переменную s, например в цикле.
s = '2020.08.31-14.15.33: {"P1":{"Location1":{"X": 266225.40625,"Y": 501808.46875,"Z": 21883.58984375},"CLocation1":{"X": 266225.40625,"Y": 501808.46875,"Z": 21883.58984375},"Event": false,"ProfileName": "Player","UserId": "76561198968409999","HasImmortality": false},"P2":{"Location2":{"X": 265164.625,"Y": 499088.78125,"Z": 22396.548828125},"CLocation2":{"X": 265164.21875,"Y": 499089,"Z": 22396.548828125},"Event": false,"ProfileName": "player2","UserId": "76561197996445700"},"Weapon": "AKM","TimeOfDay": "15:17:20"}'
# теперь извлекаем
players = json.loads(s.split(':', 1)[1].strip())
for index in ('P1', 'P2'):
player = players[index]
profile_name = players[index]['ProfileName']
user_id=players[index]["UserId"]
print(f'{index} {profile_name} ({user_id})')
path('bio/<username>/', views.bio, name='bio')
# или
re_path(r'^bio/(?P<username>\w+)/$', views.bio, name='bio')
f2 = open("base.txt", encoding = 'utf-8')
d = open('deleted.txt', 'a', encoding = 'utf-8')
ffinal = open("good.txt",mode = 'a',encoding = 'utf-8')
f1 = open("first.txt",mode = 'r',encoding = 'utf-8')
for line in f1:
...
f1.close()
ffinal.close()
d.close()
f2.close()