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/database-functions/#cast
> https://docs.djangoproject.com/en/2.0/ref/models/database-functions/#now

Sure, but what's the upside? The downside is that your objects are bigger, 
more data transferred from db to python layer, more complex query.

What I'm trying to conveigh here, is not to shoehorn the ORM into your notion 
of SQL, but to think in models, model fields, object properties and model 
relations.

There will be times where the ORM needs help from SQL, but pick your battles.
-- 
Melvyn Sopacua

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/4047248.Nn77cOrblS%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

Reply via email to