Approach (1), If you can assign Class to variable In Python you can directly assign a Class to a variable. If your variable holds the class you can directly call it. This is how I do it -
The model -
class ErrorLog(models.Model):
class Meta:
app_label = 'core'
The url config, passing Model Class
in variable -
url(r'^' ..., GenericListView.as_view(..., model=ErrorLog,...), name='manage_error'),
Then finally calling the query set in the view -
class GenericListView(...):
model = ....
def get_queryset(self):
//other codes
return self.model.objects.all()
You see the query_set will return whatever class mentioned in it.
Approach (2), if you only has the class name But in case, your variable only contains string
name of the 'Class
but not the class directly then you might wanna get the model before calling the queryset -
to get the model class you can do the following -
from django.db.models import get_model
model = get_model("string name of model class")
return model.objects.all()