rank
Enable SQL Window functions for use in Django queries. Add rank to your query.
Django in curren’t version (1.10) doesn’t support [window functions](https://www.postgresql.org/docs/9.3/static/functions-window.html) as seen in PostgreSQL. This implemets rank, dense_rank and adds shortcut for upper_rank, which retrieves upper value for rank (rank of last element in the window). The implementation is currently working only on PostgreSQL.
Note: The support for window functions is being already solved in [issue #26608](https://code.djangoproject.com/ticket/26608).
Quickstart
Install rank:
pip install django-rank-query
Usage
U can annotate users by rank (sequenc number in alphabet) of their last name the like this:
from rank import DenseRank, UpperRank, Rank
users = User.objects.all()
users = user.annotate(lower_rank=Rank('last_name'))
users = user.annotate(upper_rank=UpperRank('last_name'))
users = user.annotate(dense_rank=DenseRank('last_name'))
Then you have user query annotated with various ranks. You can retrieve them for example by values function:
user_ranks = users.values('last_name', 'lower_rank', 'upper_rank')
Note: PostgreSQL doesn’t support combining rank functions with GROUP_BY or in WHERE clause. So you cannot use them in aggregation queries.
Rank is counted in the current select query, so filtering will change rank of given elements, so you can’t have sequence number in whole table filtered by ie. his name. This can be solved by using subqueries in SQL, but Django doesn’t support them as far as I know.
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.1.0 (2017-01-20)
First release on PyPI.
Metadata
Release files for django-rank-query 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-rank-query-0.1.0.tar.gz | 16.5 kB | Without provenance | Details for django-rank-query-0.1.0.tar.gz |
Release files / django-rank-query-0.1.0.tar.gz
| Download URL | django-rank-query-0.1.0.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6eef9d1c4048977494cc89be241d4c36a53a485ef00d4aedf2c974d0c70f941f
|
|
BLAKE2b-256 checksum How to use checksums |
036da0af2e03979daa744d018f23931a59a9d3fd3b1696ce86c33955c1f45489
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-rank-query 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.