update values in loop
This commit is contained in:
parent
664f081b9f
commit
ecc886689e
|
@ -21,6 +21,12 @@ class TmcElementSerializer(serializers.Serializer):
|
|||
count = serializers.IntegerField()
|
||||
|
||||
|
||||
class TerritorySerializer(serializers.Serializer):
|
||||
id = serializers.IntegerField()
|
||||
name = serializers.CharField()
|
||||
count = serializers.IntegerField(required=False)
|
||||
|
||||
|
||||
class TgItemSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = TgItem
|
||||
|
@ -37,7 +43,10 @@ class TgStatItemSerializer(serializers.Serializer):
|
|||
if not obj.get("location__parent"):
|
||||
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"))
|
||||
for q in queryset:
|
||||
q.count = location_parent_ids.count(q.id)
|
||||
serializer = TerritorySerializer(queryset, many=True)
|
||||
else:
|
||||
queryset = Territory.objects.get(id=obj.get("location__parent"))
|
||||
|
|
|
@ -147,13 +147,15 @@ class TmcStatViewset(viewsets.ViewSet):
|
|||
.values("tmc__tmc_id")
|
||||
.annotate(
|
||||
inv_count=Count("location__parent"),
|
||||
tmc_count=Count("tmc__tmc_id", distinct=True)
|
||||
tmc_count=Count("id", distinct=True)
|
||||
)
|
||||
.annotate(
|
||||
location__parent=ArrayAgg("location__parent"),
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue