Get latest object with filter in django rest framework
<p>When I request GET through DRF API, I want to return the latest object.
I tried this one in views.py: </p>

<pre><code>class ListCreateNodeConfig(generics.ListCreateAPIView):
    queryset = models.NodeConfig.objects.all()
    serializer_class = serializers.NodeConfigSerializer

    def get_queryset(self):
        return self.queryset.filter(node_id=self.kwargs.get('node_pk')).latest('timestamp')
</code></pre>

<p>But it throws error: 'NodeConfig' object is not iterable</p>

<p>models.py</p>

<pre><code>class NodeConfig(models.Model):  
    node_id = models.ForeignKey(Node)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    record_interval = models.IntegerField(default=0)
    lower_frequency = models.IntegerField(default=0)
    upper_frequency = models.IntegerField(default=0)
</code></pre>

<p>How to fix it? </p>

<p>Any suggestions are appreciated. </p>