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

How to use Django Bootstrap Modal Forms

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

Documentation is Very vital before you develop any system or app