Using extra field in Annotate Django

Asked

Viewed 88 times

1

I’m trying to add a column called today in a Model with the .extra(), to work on a annotate. I’m not finding it. He’s not finding the field.

duration = ExpressionWrapper(F('today') - F('pub_date'), output_field=fields.DurationField()) 
list_posts = posts.extra(select={'today': "now()"}).annotate(duration=duration)

Error

Cannot resolve keyword 'today' into field.

Observing It does not display Today in the list of possible fields or anything like it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.