I am trying to make a model selection using a relationship with a shared foreign key, but it does not work properly.
I think this is better illustrated and understood with code.
class ModelA(models.Model): created = models.DateTimeField(auto_now_add=True) class ModelB(models.Model): instanceA = models.ForeignKey(ModelA) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() class ModelC(models.Model): number = models.PositiveIntegerField() bInstances = generic.GenericRelation(ModelB)
To be clear, I would like this line to work: ModelA.objects.filter(modelb__content_object=modelCInstance) , apparently django does not support the use of content_object in filter relationships.
Thanks in advance!
django django-models
Clash
source share