Sri Harsha
Sri Harsha

Reputation: 107

Django .latest() values

I'm using django for my project. I have a model(table) in which the data is filled by running a process. Each process has threesteps , so all the seven steps are seven rows in table. Below is the sample table:

RunId   Process   ID

403     step1     1
403     step2     2
403     step3     3

404     step1     4
404     step2     5
404     step3     7

Each process has a RunId which is unique to each process. In the front-end, I have a table which shows the process which are run currently now and the current step in which the process is.

To get the current step, I used the following django code:

RunIds = [403,404]
model.objects.filter(RunId__in = RunIds).latest()

which gives the last row of each process (that is step 3 in above table). But when I wanted to see the values of the object, I ran the following command:

model.objects.filter(RunId__in = RunIds).latest().values()

Django showed an error saying values() is not an attribute of model because .latest() doesn't give queryset. The problem is , i'm not able to convert the data in that object to a dictionery so that I can update the dictionery with other values and dictioneries using dict.update().

Upvotes: 3

Views: 3432

Answers (1)

Enthusiast Martin
Enthusiast Martin

Reputation: 3091

.latest() returns the actual object, not queryset.

So you try to call values on your model object, which it does not have.

Swap the order:

model.objects.filter(RunId__in = RunIds).values().latest()

Upvotes: 8

Related Questions