Answer the question
In order to leave comments, you need to log in
How to pass Django model name to a function?
How to pass Django model name to a function?
view:
def get_obj(model_name, id):
try:
obj = models.model_name.objects.get(id=id)
except (ObjectDoesNotExist, ValueError, TypeError):
obj = None
return obj
post = self.get_obj('Post', post_id)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question