Question

I am trying to retrieve a generic object like so:

generic_type = ContentType.objects.get(app_label="customers", model="Customer")
print generic_type.id 
print 'customer: '+str(customer.id)
setting = generic_type.get_object_for_this_type(object_id=customer.id)

Both print statements spit out the proper values stored in my database.

I am following the retrieval as found in the docs here: https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#django.contrib.contenttypes.models.ContentType

I am running django 1.4.3

Is there anything wrong with my retrieval method?

Was it helpful?

Solution

This can be done with the following:

generic_type = ContentType.objects.get_for_model(customer)
setting = Preference.objects.filter(content_type__pk=generic_type.id, object_id=customer.id)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top