Models:
- Employee - name, email
- CuttingJob - employee (ForeignKey), count
- OrderCuttingDetail - product_name, amount
I want to show the employee wise cutting count and it’s amount.
employees = Employee.objects.annotate(
total_cutting_job_count=Sum(‘cutting_jobs__count’),
total_cutting_job_amount=ExpressionWrapper(F(‘total_cutting_job_count’) * F(‘cutting_jobs__order_cutting_detail__amount’), output_field=DecimalField()),
).all()
But while running this query, employees are duplicated. Need to group the records based on employee’s name.
Kindly suggest a solution for this.