Re: Query annotation with date difference

2016-09-04 Thread Peter of the Norse
I would use the DB NOW() function for this.  https://docs.djangoproject.com/en/1.9/ref/models/database-functions/#nowfrom django.db.models.functions import Now.annotate(ratio=(F(‘due_date')-Now())/F('Interval'))On Aug 3, 2016, at 3:34 PM, Constantine Covtushenko

Re: Query annotation with date difference

2016-08-03 Thread Constantine Covtushenko
Sorry, I did not specify. I have been using 'Postgresql' with 'psycopg2 v.2.6.2'. They gave me those results. Also here is a sql query given from log: SELECT "test_app_entity"."id", "test_app_entity"."due_date", "test_app_entity"."interval", (("test_app_entity"."due_date" - '2016-08-03T21:31:58.32

Re: Query annotation with date difference

2016-08-03 Thread Yoann Duriaud
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.7437

Re: Query annotation with date difference

2016-08-02 Thread Constantine Covtushenko
Ok, I am ready. I did exactly as I suggested and got *successful* result. Please check screenshots below: on admin: [image: Inline image 1] on table view with annotated field: [image: Inline image 2] were -model class Entity(models.Model): due_date = models.DateTimeField(default=timezone.now

Re: Query annotation with date difference

2016-08-01 Thread Constantine Covtushenko
Hi, I am not cleat of what you suggested as a dictionary method and how you are going to use it. But any way let me check my guesses and I will be back. On Mon, Aug 1, 2016 at 11:25 PM, Yoann Duriaud wrote: > Thanks for the tip, but besides defining the type of the output it is > unclear how t

Re: Query annotation with date difference

2016-08-01 Thread Yoann Duriaud
Thanks for the tip, but besides defining the type of the output it is unclear how this can be used to perform a date difference operation. What I would need is to convert *timezone.now()* into a date constant that can be understood by the database, whatever the database is. If I leave it as it

Re: Query annotation with date difference

2016-07-31 Thread Constantine Covtushenko
Hi Yoann, I am not sure exactly but believes you are on the right way. Try improve your expression with ExpressionWrapper, as said here . Probably the problem is that you use values of different types in your

Query annotation with date difference

2016-07-30 Thread Yoann Duriaud
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'))