I have a query object Conversation that has certain attributes.Below is the model defined for it
class Conversation(models.Model):
timestamp = models.DateTimeField(auto_now=True)
context_name = models.CharField(max_length=100)
user = models.CharField(max_length=50)
type = models.CharField(max_length=10)
data = models.TextField(null=True)
feedback = models.CharField(max_length=10, null=True)
Now I want to access the attributes of the queryset object.If I use the below query
serializers.serialize("json", Conversation.objects.all())
I am able to get all the attributes.But if I want the attributes based on a latest timestamp, I am unable to get it.I tried the below query
serializers.serialize("json", Conversation.objects.latest("timestamp"))
I am expecting a JSON for the latest timestamp but I get the error as TypeError: 'Conversation' object is not iterable
.
However I am able to access the individual attributes like Conversation.objects.latest("timestamp").context_name
but not all of them for the latest timestamp.
How can I achieve this?