Skip to content Skip to sidebar Skip to footer

Python/django: Model Object Has No Attribute 'prefetch_related'

I have created a model 'VehicleDetails' in which a user can fill the details of a vehicle and another model 'TripStatus' in which he updates the vehicle location. I wanted to get t

Solution 1:

prefetch_related works on a queryset object. Latest returns a single model not a queryset.

This should work :

tripstatus = TripStatus.objects.all().prefetch_related('statuses').latest('statustime')

Post a Comment for "Python/django: Model Object Has No Attribute 'prefetch_related'"