I am working on a django project, and taking over the project from other developers as they have left the project. I came across a query which I am not able to understand how it works, This is the query in question.
provider_evaluations = ProviderEvaluation.objects.filter(
customer_provider_relation_id__projectproviders__project_id=project_id,
customer_provider_relation_id__provider_id=provider_id,
and these are the models included in the query.
class ProviderEvaluation(models.Model):
provider_evaluation_criterias_id = models.ForeignKey(ProviderEvaluationCriterias, on_delete=models.CASCADE, null=True)
evaluation = models.CharField(max_length=255, null=True)
comment = models.TextField(null=True, blank=True)
created_by = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, null=True)
workflow_step = models.ForeignKey(WorkflowStep, on_delete=models.CASCADE, default=None, null=True)
customer_provider_relation_id = models.ForeignKey(CustomerProviderRelation, on_delete=models.CASCADE, null=True, default=None)
def __str__(self):
return f"{self.provider_evaluation_criterias_id} - {self.evaluation}"
class CustomerProviderRelation(models.Model):
customer_tenant_type = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
related_name='customer_tenant',
limit_choices_to={'model__in': ['customer']},
)
provider_tenant_type = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
related_name='provider_tenant',
limit_choices_to={'model__in': ['provider']},
)
customer_tenant_id = models.PositiveIntegerField()
provider_tenant_id = models.PositiveIntegerField()
customer_tenant = GenericForeignKey('customer_tenant_type', 'customer_tenant_id')
provider_tenant = GenericForeignKey('provider_tenant_type', 'provider_tenant_id')
customer_id = models.ForeignKey(Customer, on_delete=models.CASCADE)
provider_id = models.ForeignKey(Provider, on_delete=models.CASCADE)
def save(self, *args, **kwargs):
# Assign values to content type and object ID fields based on the instance being saved
if isinstance(self.customer_tenant, Customer):
self.customer_tenant_type = ContentType.objects.get_for_model(Customer)
self.customer_tenant_id = self.customer_tenant.id
if isinstance(self.provider_tenant, Provider):
self.provider_tenant_type = ContentType.objects.get_for_model(Provider)
self.provider_tenant_id = self.provider_tenant.id
super().save(*args, **kwargs)
def __str__(self):
return f"CustomerProviderRelation ID: {self.id}"
class ProjectProviders(models.Model):
STATE_CHOICES = [
('searched', 'Searched'),
('initiated', 'Initiated'),
('completed', 'Completed'),
('closed', 'Closed'),
('rejected', 'Rejected'),
]
project_id = models.ForeignKey(Project, on_delete=models.CASCADE)
customer_provider_relation_id = models.ForeignKey(CustomerProviderRelation, on_delete=models.CASCADE)
shortlisted=models.BooleanField(default=False)
state = models.CharField(max_length=20, choices=STATE_CHOICES)
workflow_run_id = models.ForeignKey(WorkflowRun, on_delete=models.CASCADE,default=None)
params = models.TextField()
delisted = models.BooleanField(default = False)
def __str__(self):
return f"ProjectProviders ID: {self.id}"
I have tried running the query in django shell which returns the result, but I am not able to understand how, also I referred documentation but could not find what this type or query is called or how it works.
3