update values in loop

This commit is contained in:
Kseninia Mikhaylova 2024-08-22 16:38:04 +03:00
parent b45d0029ae
commit f63a9ef6b3
3 changed files with 7 additions and 7 deletions

View File

@ -22,7 +22,7 @@ class TmcElementSerializer(serializers.Serializer):
class TerritorySerializer(serializers.Serializer):
id = serializers.IntegerField(required=False)
id = serializers.IntegerField()
name = serializers.CharField()
count = serializers.IntegerField(required=False)
@ -44,7 +44,7 @@ class TgStatItemSerializer(serializers.Serializer):
return None
if isinstance(obj.get("location__parent"), list):
location_parent_ids = obj.get("location__parent")
queryset = Territory.objects.filter(id__in=obj.get("location__parent")).values('name')
queryset = Territory.objects.filter(id__in=obj.get("location__parent"))
for q in queryset:
q.count = location_parent_ids.count(q.id)
serializer = TerritorySerializer(queryset, many=True)

View File

@ -154,8 +154,7 @@ class TmcStatViewset(viewsets.ViewSet):
tmc=ArrayAgg("tmc"),
)
)
logger.info(queryset)
# logger.info(queryset)
# logger.info(TgItem.objects.all().values())
serializer = TgStatItemSerializer(queryset, many=True)
return Response(serializer.data)
# return Response()

View File

@ -34,20 +34,21 @@ const getData = async () => {
<UButton :disabled="!isOrg" @click="getData">По продуктам</UButton>
</UButtonGroup>
</div>
<UCard v-for="item in data" class="col-span-4" v-if="data && isOrg">
<UCard v-for="item in data" class="col-span-4" v-if="data && isOrg == true">
<template #header>
{{ item.location.name }} <UBadge>{{ item.inv_count }}</UBadge>
</template>
<UTable :rows="item.tmc" />
</UCard>
<UCard v-for="item in data" class="col-span-6" v-if="data && !isOrg">
<UCard v-for="item in data" class="col-span-6" v-if="data && isOrg == false">
<template #header>
<template v-for="el in item.tmc">
{{ el.tmc__name }}, всего {{ el.count }}
</template>
<UBadge>{{ item.inv_count }}</UBadge>
</template>
<UTable :rows="item.location" />
<UTable :rows="item.location"
:columns="[{ key: 'name', label: 'name' }, { key: 'count', label: 'count' }]" />
</UCard>
</div>
</template>