RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
would use the annotation for a report that shows counts based on certain criteria. -Original Message- From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Melvyn Sopacua Sent: Monday, May 14, 2018 4:32 PM To: django-users@googlegroups.com Subject: Re: SQL s

Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On maandag 14 mei 2018 16:42:49 CEST Matthew Pava wrote: > But if in your use case, you had a million records in which you were trying > to filter Full stop right there. No one is filtering anything in the original use case, so you're comparing apples and oranges. Filtering you would do in the d

RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
go-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Melvyn Sopacua Sent: Monday, May 14, 2018 9:29 AM To: django-users@googlegroups.com Subject: Re: SQL select statements to Django ORM On maandag 14 mei 2018 15:38:01 CEST Matthew Pava wrote: > You could use the ORM to get the dif

Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On maandag 14 mei 2018 15:38:01 CEST Matthew Pava wrote: > You could use the ORM to get the difference of two dates like so: > Person.objects.annotate(age=ExpressionWrapper(Cast(Now(), DateField()) - > F('dob'), output_field=DurationField())) > https://docs.djangoproject.com/en/2.0/ref/models/datab

RE: SQL select statements to Django ORM

2018-05-14 Thread Matthew Pava
en/2.0/ref/models/database-functions/#now -Original Message- From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Melvyn Sopacua Sent: Monday, May 14, 2018 5:56 AM To: django-users@googlegroups.com Subject: Re: SQL select statements to Django ORM On zon

Re: SQL select statements to Django ORM

2018-05-14 Thread Melvyn Sopacua
On zondag 13 mei 2018 03:44:37 CEST Gerald Brown wrote: > As I have said previously, I am new to Django ORM so I would like to know > howto/find reference to Django ORM Query to the following SQL Select > statements: Do you want to use SQL or use Django? Pick one. > 1. From Mariadb. > > SELECT n

Re: SQL select statements to Django ORM

2018-05-13 Thread Todor Velichkov
You can use Raw SQL expressions only for the custom field which you want to annotate. MyModel.objects.all().annotate(age=RawSQL("TIMESTAMPDIFF(YEAR, date_of_birth, curdate( On Sunday, May 13, 2018 at 4:4