Django Python


Using get method to return a single column with instance of the fields.
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



Comments

Popular posts from this blog

Documentation is Very vital before you develop any system or app

Steps followed when creating a new software

Everything you need to know when developing an on demand service app