Django Nested Query

Here is my view.py

class ItemFilter(filters.FilterSet):
    stk_no=filters.CharFilter(lookup_expr="icontains")
    itemtran__ledindi=filters.CharFilter(lookup_expr="iexact")
    part_no=filters.CharFilter(lookup_expr="icontains")   
    brand_name=filters.CharFilter(lookup_expr="icontains")   
    class Meta:
        model=Item
        fields=['stk_no','itemtran__ledindi','part_no','brand_name']

class ItemViewSet(viewsets.ModelViewSet): 
    serializer_class = ItemSerializer
    queryset = Item.objects.all()  
    filter_backends = [DjangoFilterBackend]    
    filterset_class = ItemFilter
    pagination_class = PostPagination

    def get_queryset(self):
        return self.queryset.filter()

Here is my serializer.py

class ItemTranSerializer(serializers.ModelSerializer):   
    id = serializers.IntegerField()
    
    class Meta:
        model = ItemTran
        read_only_fields = (
            "stk_no_id", 
        ), 
        fields = (
            "id",
            "stk_no",
            "qty", 
            "trntype",
            "company",
            "department",
        )


class ItemSerializer(serializers.ModelSerializer):   
      
    itemtran = ItemTranSerializer(many=True)
    
    class Meta:
        model = Item
        read_only_fields = (
            "created_at",
            "created_by",
        ), 
        fields = (
            "id",
            "stk_no",
            "part_no",
            "brand_name",
            "itemtran", 
        )

Im trying to filter all items with the "company" field in "ItemTran" filtered. but the api just returns all the transactions.

            "id": 7614,
            "stk_no": "NT1515",
            "part_no": "185/65 R 15",
            "brand_name": "Brand X",
            "itemtran": [
                {
                    "id": 620855,
                    "stk_no": "NT1515",
                    "qty": 4.0,
                    "trntype": "INV",
                    "company": "I",
                    "department": "I"
                },
                {
                    "id": 632238,
                    "stk_no": "NT1515",
                    "qty": 2.0,
                    "trntype": "ARR",
                    "company": "A",
                    "department": "F"
                },

where i only need the "itemtran" to show only company "I" rows.

i pretty new at this so please any help is greatly appreciated.

i have a similar module which works but cant figure out whats wrong here i tried rewriting the whole thing from scratch and still not result

Back to Top