Thank you, this is exactly what I was looking for

-Josh
On Wednesday, September 7, 2022 at 5:47:18 PM UTC-6 Thomas wrote:

> Something like qs.aggregate(delay=Avg(F(“approved_at”) - 
> F(“created_at”)))[“delay”]
>
> where I cribbed the technique from 
> https://stackoverflow.com/questions/50219652/django-queryset-get-avg-of-2-fields
>
> hth
>
> - Tom
>
> On Sep 6, 2022, at 3:13 PM, Joshua Corlin <joshua...@gmail.com> wrote:
>
> Hello Everyone, 
>
> This is my first posting on this forum, please let me know if I have done 
> anything incorrectly.  
>
> I have a seemingly simple task I am trying to achieve with one of my 
> projects.  Looking to see if the following is possible, and if so what the 
> syntax would be with the Django ORM.  Apologies in advance if this is a 
> trivial one. 
>
> I have a requests model that has a bunch of time stamps(6 to be specific) 
> and these timestamps record milestones in the request, set throughout the 
> lifecycle of a request.  Im trying to write a query that gets a set of 
> records, calculates the difference between two timestamps and averages 
> those differences over the queryset.  For example, i want to get the 
> average amount of time between the created_at timestamp and an approved_at 
> timestamp over a set of records.  
>
> I seem to be able to do this in postgres with the following, how can I do 
> this with the Django ORM? 
>
> select avg(approved_at - created_at) as approval_time from 
> dashboard_labrequest;
>
> Thanks in advance!
>
> -- 
> 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...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/da6f1f06-e036-46ce-9405-520004de18afn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/da6f1f06-e036-46ce-9405-520004de18afn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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/b4f6f308-37d8-4ea4-b63b-9803c3ebbdb4n%40googlegroups.com.

Reply via email to