ct = ContentType.objects.get(app_label="myapp", model="mymodel")
# or
ct = ContentType.objects.get_for_model(MyModel)
# Get the class associated with the content type
model_cls = ct.model_class()
# Filter the queryset as normal
queryset = model_cls.objects.filter()
# Get a specific object instance given a content type
ct.get_object_for_this_type(username='Guido')
http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/
No comments:
Post a Comment