#24485: Support for annotate(end=F('start') + F('duration'),
output_field=DateTimeField)
-------------------------------------+-------------------------------------
Reporter: yoyoma | Owner: jarshwah
Type: New feature | Status: new
Component: Database layer | Version: 1.8beta2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: durationfield, | Triage Stage: Ready for
aggregation, annotation | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by yoyoma):
* status: closed => new
* resolution: fixed =>
Comment:
Sorry to reopen this ticket, guys. I've been so busy the past few days I
didn't get a chance to try out the new code / docs until after work
tonight. The issue with the docs update and code updates, as I see them,
is that {{{Expression}}} takes only 2 arguments, namely {{{self}}} and
{{{output_field}}}, so the example in the docs (fitted to my schema):
{{{
from django.db import models
from myapp.models import Ticket
Ticket.objects.annotate(
expires_at=models.Expression(
models.F('active_at') + models.F('duration'),
output_field=models.DateTimeField()
)
)
}}}
results in {{{TypeError: __init__() got multiple values for argument
'output_field'}}}
The aforementioned (by @jarshwah) method of simply adding an
`output_field` to an a combined {{{F}}} didn't work either:
{{{
expires_at = models.F('active_at') + models.F('duration')
expires_at.output_field = models.DateTimeField()
Ticket.objects.annotate(expires_at=expires_at)
}}}
That resulted in:
{{{
django/db/models/query.py in iterator(self)
259 if annotation_col_map:
260 for attr_name, col_pos in
annotation_col_map.items():
--> 261 setattr(obj, attr_name, row[col_pos])
262
263 # Add the known related objects to the model, if there
are any
AttributeError: can't set attribute
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24485#comment:16>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.34ae009874b4121b099e908806acb376%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.