You can use Raw SQL expressions 
<https://docs.djangoproject.com/en/2.0/ref/models/expressions/#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:44:37 AM UTC+3, 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:
>
> 1. From Mariadb. 
>
> SELECT name, date_of_birth, *TIMESTAMPDIFF(YEAR,date_of_birth,'2014-08-02'/or 
> curdate())* AS age FROM some table.
>
> 2. General SQL statement
> SELECT field1, field2, field10 from some table
>
> 3. How to see all of the data from those statements which SQL shows me. 
>
> I have read (several times) the documentation @ 
> https://docs.djangoproject.com/en/2.0/topics/db/queries/. They show numerous 
> examples of Queries but none of them show the results from those queries.
>
> When I do get results to show ONLY the fields that are in my __str__ 
> statement show up. If I add additional fields they also
> show up in my FK list, which I don't want.
>
> Thanks for all previous help from this group.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cf4049e1-fefe-4669-ad7c-5bc53782829c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to