In my application, i have a model definition like:
class SomeModel(models.Model):
someFK = Models.ForeignKey(SomeModel, null=True, blank=True)
otherFK = Models.ForeignKey(OtherModel, null=True, blank=True)
...
This model keep data about Logs, and there are more than 1 kind of model to be logged, so i place a FK for each related Model. For each record, only one of the FK's is used, other FK's set NULL = True.
But i do not wish to alter my model when i need to log some other thing. So i alter my model so:
class SomeModel(models.Model):
content_type = models.ForeignKey(ContentType)
content_id = models.IntegerField()
So i used following to get what i want:
content_type.get_object_for_this_type(id=content_id)
Its ok. But when admin.py comes into play, it causes problem, because i have 1.000.000+ data for some related models to be logged, so i need to use raw_id_fields. Since i do not have FK for each related model, i must use ContentType model and content_id, but i do not know how to do that using ContentType?