V
V
vladibuyanov2021-03-17 12:31:12
Django
vladibuyanov, 2021-03-17 12:31:12

How to work with query set in Django?

I have a problem with query set processing.
I have a similar code:

def index(request):
    results = ResultInput.objects.all()
    return render(request, 'main/index.html', {'title': 'Main page', 'results': results})


I would like to implement
n = 0
ihst = []
while len(results) != n:
     ihst.append((results[n].time * 100) / (results[n].f1+results[n].f2+results[n].f3)*2)
     n += 1
print(ihst)


Accordingly, it would be desirable not to do it through while. I wrote this here because it works. How to interact with the query set in general? As I understand it, this is not an iterable object and it will not work to access through for in.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-03-17
@vladibuyanov

How to interact with the query set in general? As I understand it, this is not an iterable object and it will not work to access through for in.
and let's start reading the docks https://docs.djangoproject.com/en/3.1/ref/models/q... so you don't write such nonsense anymore

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question