Skip to main content

Natural sorting for Django CharFields.

Project description

Better ordering for CharFields. Ignores spaces at the start of a string, does the right thing with integers. Removes “the” at the start of strings, if you’re using naturalsortfield.en.

Example:
>>> from django.db import models
>>> from naturalsortfield.en import NaturalSortFieldEn
...
>>> class MyModel(models.Model):
...     title = models.CharField(max_length=255)
...     title_sort = NaturalSortFieldEn()
...
>>> MyModel.objects.create(title='XYZ 10')
>>> MyModel.objects.create(title='XYZ 1')
>>> MyModel.objects.create(title='ABC')
>>> MyModel.objects.create(title='The XYZ 2')
>>> [obj.title for obj.title in MyModel.objects.order_by('title_sort')
['ABC', 'XYZ 1', 'The XYZ 2', 'XYZ 10']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-naturalsortfield-0.7.tar.gz (2.6 kB view details)

Uploaded Source

File details

Details for the file django-naturalsortfield-0.7.tar.gz.

File metadata

File hashes

Hashes for django-naturalsortfield-0.7.tar.gz
Algorithm Hash digest
SHA256 ff9803a80bc40c4f9271ff902c241b885ee423ba1b2765ddc6573b54a4dbd83c
MD5 774b272ac52b7b70fecb5e81997dbdc9
BLAKE2b-256 279ea3c78f24155ca278bc0b7b5968a9b812c6c58030489a7d8415712c9a7639

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page