E
E
Enter_a_nickname2022-04-01 15:35:36
Django
Enter_a_nickname, 2022-04-01 15:35:36

How to get the last entry from the database by user?

A selection from the database by user is implemented as follows:
return self.request.user.leads.all()
But I need to get not all the data, but only the last record.
I tried to implement it through the last:
return self.request.user.leads.all().last()
But the error comes in response:

TypeError: 'LeadModel' object is not iterable

How to get the latest entry?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-04-01
@bacon

last() is one specific record, why are you trying to iterate over it, it's not clear. Well, once again, always show the full traceback of the error
PS what does DRF have to do with it is not clear, you provide code where only django is used and there is no hint of drf

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question