model_name = "MyModel" #This is coming from a different input, it can be any different string name not necessarily "MyModel"
model_name.objects.filter()
AttributeError: 'str' object has no attribute 'objects'
How can I make this work, I have already tried:
exec(model_name)
input(model_name)
[model_name]
I know there is a possible method where you import the model using apps.get_model(model_name="string")
but I don't want to use this method due to the model already being imported beforehand. Is there any different way where I can convert model_name (string type) to a type that can be inserted at INSERTHERE.objects.filter()
Update: I know an easier implementation would be to use if + elif statements to query the correct model. I'm trying to find a way to avoid using if + 100 elif statements..