Thanks, unfortunately not so great on my side: I added in the query (forgetting the division for now):
.annotate(ratio=ExpressionWrapper(F('due_date')-timezone.now(), DateTimeField())) which leads to the following statement in the query: ("contentstatus"."due_date" - 2016-08-03 21:05:10.743799+00:00) AS "ratio" This is not a valid SQL statement (at least for SQLite) and leads to the following error message when the query is evaluated: Exception Type: TypeError Exception Value: expected string or bytes-like object Any idea what I get this behavior? Yoann Le samedi 30 juillet 2016 22:41:21 UTC+2, Yoann Duriaud a écrit : > > Hello, > I would like to annotate a query with the following expression: ([Due > Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the > database, while [Now] should be "equal" to timezone.now(). > > So this would look like: > .annotate(ratio=(F('due_date')-timezone.now())/F('Interval')) > > but this does not work. Does someone know how the expression should be > written (if it is indeed feasible with Django ORM)? > > Thanks for your help! > > Yoann > -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/038837c5-6b5b-4ae9-895a-b6b54282d978%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.