Reputation: 65
i am selecting last object from my table using following Code
data= MyModel.objects.last()
This is Displaying object. i want to display full array of 'data' object.for that i am using Following Code
data= MyModel.objects.last().values()
However its not Working.How to do that?
Upvotes: 4
Views: 2426
Reputation: 476594
You should swap .values(…)
[Django-doc] and .last()
[Django-doc], since before the .last()
, you are working with a Manager
or QuerySet
, after .last()
you are working with a MyModel
object:
data= MyModel.objects.values().last()
That being said, using .values()
is often not a good idea. It erodes the logic layer a model provides. Only in specific cases, like a GROUP BY
on a certain value it is a good idea to use .values()
.
Upvotes: 4