1
If self.object
is a Model3
instance, you could:
Model1.objects.filter(distributor_links__link=self.object)
This quiestion is similar to: Django โ How to use a filter with a foreign key field?
That is, the name of the field, followed by a double underscore (__), followed by the name of the field in the new model, and so on for as many models as you want to join.
For more information: https://docs.djangoproject.com/en/dev/ref/models/querysets/
1
Is it possible to resolve ContentType of object and use it and object id for filtering.
content_type = ContentType.objects.get_for_model(self.object)
Model1.objects.filter(distributor_links__content_type=content_type, distributor_links__object_id=self.object.id)
- [Answered ]-Updating Records with image field in Django?
- [Answered ]-Django inclusion tag takes_context TemplateDoesNotExist error
- [Answered ]-Is there a way to test methods with a lot of raw_input in django?
- [Answered ]-Django queryset select where concat
Source:stackexchange.com