D
D
dustik2014-02-27 13:23:31
Django
dustik, 2014-02-27 13:23:31

How to implement the selection of the value with the maximum id in the model (table) in Django?

Hello.
I ask you to suggest whether it is possible to elegantly for the table 'table1', the code of the selection from which is given below:

>>> table1.objects.all().values_list('id','value1')
[(5L, 152449L), (6L, 12L), (7L, 999L), (8L, 11777L)]

select the value of the 'value1' field for which 'id' will be the maximum.
While a monstrous construction in python or pure sql comes to mind.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
laQie, 2014-02-27
@dustik

>>> table1.objects.latest('id').value1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question