'QuerySet' object has no attribute '_meta'
Late answer but worth it.
from django.shortcuts import get_object_or_404
...
def get_object(self, queryset=None):
obj = get_object_or_404(Staff, pk=self.kwargs['staff_id'])
return obj
This approach will return HTTP 404 Not Found
response if object not found.
The get_object
method returns queryset
i.e list of records, instead of instance
.To get instance
you can use first()
on filter()
. This will gives you first occurrence.
def get_object(self, queryset=None):
obj = Staff.objects.filter(pk=self.kwargs['staff_id']).first()
return obj