I have a typical definition/instance situation in my data modeling. I'm trying to store the content_type of a GenericForeignKey
in another model (the definition model) like so:
class IndicatorFieldInstance(models.Model):
definition = models.ForeignKey(IndicatorField)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey(definition.content_type, 'object_id')
indicator_instance = models.ForeignKey(IndicatorInstance)
I've also tried it like this:
content_object = generic.GenericForeignKey('definition__content_type', 'object_id')
Neither of these methods seem to work. Is it possible to achieve this?
For reference, here's the definition model:
class IndicatorField(models.Model):
name = models.CharField(max_length='255')
content_type = models.ForeignKey(ContentType)
indicator = models.ForeignKey(Indicator)
Thanks, Pete