Tastypie get latest record -
instead of returning multiple objects when id isn't set. i'd return one, latest.
# return latest entry /api/entry/ {'id': 2, 'foo': 'bar', ...} # return specified entry /api/entry/1/ {'id': 1, 'foo': 'bar', ...}
i've tried overriding both obj_get_list
, get_object_list
, neither worked me.
do need create view this?
using aniav's solution, , adding necessary modifications:
resource class meta: max_limit=1 get_object_list(self,request): return super(self, resource).get_object_list(request).filter(user=request.user).order_by('-date')
where of course date replaced field want latest of.
Comments
Post a Comment