A
A
Alexander2018-09-30 19:51:02
Django
Alexander, 2018-09-30 19:51:02

How to limit the number of results per output from the database?

In views.py there is a code How to limit the number of displayed results, for example, five if the table has 15 rows? Also, I wonder how to make these results always random, that is, he took random 5 rows out of these 15.
tags = Tags.objects.filter(is_active=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-09-30
@AleksandrB

Tags.objects.filter(is_active=True)[:5]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question