Skip to content

farsounder/drf-multifield-cursor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-field cursor pagination implementation for Django Rest Framework.

Allows multiple fields to be used for cursor pagination

The built-in cursor pagination in DRF relies on the main field that you're paginating on to be 'sufficiently' unique, even if multiple fields are provided to use as the ordering (and those fields guarantee unique ordering). This is an update, posted orignally as a PR against the DRF project by sonthonaxrk.

Relevant links:

The use case this solved for me was ordering on time (and id) where the times were not guarunteed to be unique due to batch creation.

Small extension

In addition to the options described on the normal CursorPagintation docs - the option to write the where clause as a tuple comparsion was added. It's an implementation detail and will only work on drivers that support it.

To try it, set the use_tuple_comparison attribute to True to enable tuple comparison for the cursor. This was found to be significantly more performant on Postgres.

Running Tests

uv run pytest

Install

Clone locally and install or use gh like:

uv add git+https://github.com/farsounder/drf-multifield-curs
or.git

About

Multicolumn cursor implementation for DRF

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages