I want to get objects with the
pk I send through request but I want only one item from the
BatchLog objects that their
batch_id is same as the
pk and my query returns multiple items within that query. I just want one of them and it doesn’t matter which one it is.
def get_queryset(self): return BatchLog.objects.filter(batch_id=self.kwargs["pk"])
QuerySet<[BatchLog, BatchLog]> but I need
How can I achieve it?
You can just get the first one.
def get_queryset(self): return BatchLog.objects.filter(batch_id=self.kwargs["pk"]).first() def get_object(self): queryset = self.get_queryset() return get_object_or_404(queryset)