class Company(models.Model):
    id = models.UUIDField(primary_key = True, default = uuid.uuid4, editable = 
False)
    name = models.CharField(_('Name'), max_length=64)


class Approval(models.Model):
 id = models.UUIDField(primary_key = True, default = uuid.uuid4, editable = 
False)
    company = models.ForeignKey(Company, related_name=("approval_company"), 
on_delete=models.CASCADE, verbose_name = _('Company'))   
    procedure = models.ForeignKey('Procedure', 
related_name=("approval_procedure"), on_delete=models.CASCADE, verbose_name = 
_('Procedure')) 


  
class Procedure(models.Model):
    id = models.UUIDField(primary_key = True, default = uuid.uuid4, editable = 
False)
    name = models.CharField(_('Name'), max_length=255)



class Price(models.Model):

    id = models.UUIDField(primary_key = True, default = uuid.uuid4, editable = 
False)
    company = models.ForeignKey('Company', related_name=("price_company"), 
on_delete=models.CASCADE, verbose_name = _('Insurance Company')) 
    procedure = models.ForeignKey('Procedure', 
related_name=("price_procedure"), on_delete=models.CASCADE, verbose_name = 
_('Procedure'))   
    price = models.IntegerField(_('Price'), )



I have these models, i want to make a queryset that can get me the prices of 
approvals that have been created and aggregate(sum('price'))

I cant find the django way to do it, i know the postgresql raw sql which is 


select main_price.price from main_approval  inner join main_price on 
main_approval.procedure_id = main_price.procedure_id and 
main_approval.company_id = main_price.company_id ;


Keeping in mind that main is my app name


How can i translate that sql in a django way

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/218172f0-d96e-4cab-b8c5-085b7ccc7d95o%40googlegroups.com.

Reply via email to