0

I have the following models:

class Timesheet(models.Model): work_packet logged_billable_hours class WorkPacket(models.Model): type name purchase_order description class PurchaseOrder(models.Model): customer class Customer(Programme): name 

the following queries:

my_timesheet_Q3 = me.timesheets.filter(date__gte=datetime.date(2019, 9, 1), date__lte=datetime.date(2019, 11, 30)).values('work_packet', 'logged_billable_hours') my_timesheet_Q3_by_wp = my_timesheet_Q3.values('work_packet').annotate(wp_hours=Sum('logged_billable_hours')).order_by() 

produces:

[{'work_packet': 1152, 'wp_hours': Decimal('384.00')}]

to the result I would like to add:

WorkPacket.type, WorkPacket.name, WorkPacket.purchase_order, WorkPacket.description, Customer.name

I know how to achieve it in plain SQL but I don't using DJANGO ORM. Can you help?

2
  • AFAIK, You can't query things that are not in the DB. Here the verbose_name, it seems not a DB field either Commented Dec 4, 2019 at 15:23
  • Sorry a mistake it is name not verbose_name Commented Dec 4, 2019 at 15:24

1 Answer 1

1

You can add them to your .values like this using field lookups:

my_timesheet_Q3 = me.timesheets.filter( date__gte=datetime.date(2019, 9, 1), date__lte=datetime.date(2019, 11, 30)).values( 'work_packet', 'logged_billable_hours', 'work_packet__type', 'work_packet__name', 'work_packet__purchase_order', 'work_packet__description', 'work_packet__purchase_order__customer__name') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.