I have this code
class Mother:
def getList()
data['list'] = [2,3,4,5]
data = json.dumps(data)
return HttpResponse(data, mimetype='application/json', status=200)
class Child(Mother)
def getList()
/////////
In the new function Here i want to get the list and do some modification like subtract some
other list and resturn same jsonresponse
How can i do that
You’ll have to abstract out the list generation part of your code from the response returning part.
This bit of code from Mother is, while not exactly invalid, not something that can work, either:
After the first return statement, Python isn’t executing the method anymore, so the second return will never run.
Try splitting it up like this:
Now there is a
makeListmethod on the Mother object, that constructs the actual list, andgetListjust formats it into an HttpResponse object.In Child,
makeListis overridden, but starts by calling the version from Mother. After that, you can do whatever modifications you need to, and return it. When you callchild.getList(), it will use that new list, and then render it to an HttpResponse, since it inheritsgetListfrom Mother.