mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
Add a Django query helper
(imported from commit cf1f87eb4fb2b6f44ec0ebafc4cad8dcc9bc5e5c)
This commit is contained in:
10
zephyr/lib/query.py
Normal file
10
zephyr/lib/query.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
def last_n(n, query_set):
|
||||||
|
"""Get the last n results from a Django QuerySet, in a semi-efficient way.
|
||||||
|
Returns a list."""
|
||||||
|
|
||||||
|
# We don't use reversed() because we would get a generator,
|
||||||
|
# which causes bool(last_n(...)) to be True always.
|
||||||
|
|
||||||
|
xs = list(query_set.reverse()[:n])
|
||||||
|
xs.reverse()
|
||||||
|
return xs
|
||||||
Reference in New Issue
Block a user