Select a single field from database (postgresql)

23 views
Skip to first unread message

Cássio Van Helden Gameiro

unread,
Dec 19, 2014, 6:51:32 AM12/19/14
to django...@googlegroups.com
Hi, i have a database with many cars, and i want to select the last car based the hour that it was registered, can someone help me?

Thanks.

aRkadeFR

unread,
Dec 19, 2014, 7:01:08 AM12/19/14
to django...@googlegroups.com
Hello Cássio,

You first need to map your cars table with a Model in Django
(https://docs.djangoproject.com/en/1.7/topics/db/models/),
then you can construct your query something like this:

Car.objects.order_by('-registered').last()

Check out the documentation on queries here:
https://docs.djangoproject.com/en/1.7/topics/db/queries/

Have a good one,

aRkadeFR



On 12/19/2014 12:51 PM, Cássio Van Helden Gameiro wrote:
Hi, i have a database with many cars, and i want to select the last car based the hour that it was registered, can someone help me?

Thanks.
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fecb3393-d336-4aa8-8058-f6bbf9cfbfc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mario Gudelj

unread,
Dec 21, 2014, 9:16:10 PM12/21/14
to django...@googlegroups.com

Or use .latest()

Reply all
Reply to author
Forward
0 new messages