'Unable to filter data in drf

This is my model.

class RateList(core_models.TimestampedModel):
name = models.CharField(max_length=255, unique=True)
special_packages_price = models.ManyToManyField('package.PackageRateListPrice',blank=True)
processing_rate = models.ManyToManyField(ProccessingRate,blank=True)
assigned_lab = models.ForeignKey(
    "sampleregistration.LabsCredentials", null=True, blank=True, on_delete=models.CASCADE
)
is_active = models.BooleanField(default=True)

My View:

class RateListPackageDetailsAPIView(ListAPIView):
# permission_classes = (IsAuthenticated, permissions.IsBookingAdminUser)
serializer_class = serializers.RateListPackageDetailsSerializer
lookup_field = 'pk'
pagination_class = CustomPagination


def get_queryset(self):
    ratelist = models.RateList.objects.filter(id=self.kwargs.get('pk')).first()
    if not ratelist:
        return Response({"errors":[f"Rate List Does Not Exist"]},status=status.HTTP_400_BAD_REQUEST)

    return package_models.Package.objects.filter(is_active=True,org_type='homedx',test_category__isnull=False)
def get_serializer_context(self):
    context = super(RateListPackageDetailsAPIView, self).get_serializer_context()
    ratelist = models.RateList.objects.filter(id=self.kwargs.get('pk')).first()
    if not ratelist:
        return Response({"errors":[f"Rate List Does Not Exist"]},status=status.HTTP_400_BAD_REQUEST)
    context["ratelist"] = ratelist
    return context

My URL: path('ratelist-details/<int:pk>/',views.RateListPackageDetailsAPIView.as_view(), name='ratelist-special'),

I am trying to filter by package name. So package name is jump of two tables. So to get the the package name i tried with query params and returned special_packages_price__package__package__name=package_name package_nanme is query_params. But it is not working. Can somebody help? Thank you !!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source