I am trying to write a function which will take class name a argument and import that class and perform some task.
def search(**kwargs):
"""
:return:
"""
try:
model = __import__('girvi.models', globals(), locals(), kwargs['model_name'], -1)
# Do some task
return results
except Exception:
raise Exception('Model not found')
But thing is model has the class which is in kwargs['model_name'] imported successfully but how do i access it. Please can someone help me.
'module' object is not callableprint model.Customer.objects.all()But then whats the point of all of this.model nameandquery listgenerated byoperatoras a argument. Then i will performfilteron that model. That can be generic for all of model.