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


Release history Release notifications

This version
History Node

0.7

History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django-naturalsortfield-0.7.tar.gz (2.6 kB) Copy SHA256 hash SHA256 Source None Aug 7, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page