#24485: Support for annotate(end=F('start') + F('duration'), output_field=DateTimeField) -------------------------------------+------------------------------------- Reporter: yoyoma | Owner: nobody Type: New feature | Status: new Component: Database layer | Version: master (models, ORM) | Severity: Normal | Resolution: Keywords: durationfield, | Triage Stage: aggregation, annotation | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by jarshwah): So this has convinced me even more that we need some kind of wrapper type to provide a top level output_field attribute to the expression, unless someone has a nicer idea? I'd suggest something along the lines of: {{{ Ticket.objects.annotate(expires=Output(F('active_at')+F('duration'), output_field=DurationField()) }}} But I'm not sold on the name (or the look of it to be honest). In the mean time though, you can capture the output of F()+F() outside the queryset construction, and modify the output_field directly: {{{ In [16]: expires = F('active_at')+F('duration') In [17]: expires.output_field = models.DurationField() In [18]: qs = Ticket.objects.annotate(expires_at=expires) In [19]: for q in qs: ....: print(q.expires_at) ....: 2015-03-15 23:53:18.065764+00:00 2015-03-16 02:53:53.953573+00:00 2015-03-15 18:53:56.391507+00:00 2015-03-15 21:53:58.441390+00:00 }}} -- Ticket URL: <https://code.djangoproject.com/ticket/24485#comment:4> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/064.cc0f2cff2fbfbffc70d1c75e79e3ae65%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.