tags:

views:

148

answers:

2

If I have a django content_type reference (the id of the model.class and the id of the object), what's the best way to get the actual object itself?

Sounds trivial but I can't actually see an example anywhere.

A: 

Do you want get_object_for_this_type?

Dominic Rodger
+1  A: 

From memory, it is something like this:

from django.contrib.contenttypes.models import ContentType
ct = ContentType.objects.get_for_id(content_type)
obj = ct.get_object_for_this_type(pk=object_id)
Wogan