How does Django ORM connect to query the database in a loop?

there is a requirement that there is a city field in the MySQL table, and there are 200 cities under that field. Each time, 10 cities are extracted from this field in turn, such as the first 10 cities in the first extraction, 11 ~ 20 in the second extraction, 21 ~ 30 in the third extraction, and then the first one after the 200th extraction. 10 cities are extracted each time to link up the cycle. You cannot use the ID of the field to extract, because cities are often added or deleted. The number of ID does not represent the number of cities. For example, if you delete 100 cities, there are still 200 cities left, but the ID is already 300.

I don"t know how to write it with Django"s ORM. Ask for advice.

Dec.07,2021

this requires saving a state, that is, the current number. You have to keep this value, no matter how you save it. For example, after each request, mark the last item, and then take the values sequentially through the id of the tag.
the real problem to be solved is how to save this value reasonably.
because django is likely to run in multiple processes and cannot communicate between processes, this progress can only be saved to the database or cache or client.
then there is nothing more to say.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c27bf9-47e27.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c27bf9-47e27.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?