Skip to main content

Better ordering for Django CharFields.

Project description

django-naturalsortfield: Better ordering for CharFields. Ignores spaces at the start of a string, does the right thing with integers, scorns the word “the”.

Example:
>>> from django.db import models
>>> from naturalsortfield import NaturalSortField
...
>>> class MyModel(models.Model):
...     title = models.CharField(max_length=255)
...     title_sort = NaturalSortField()
...
>>> MyModel.objects.create(title='ABC')
>>> MyModel.objects.create(title='XYZ 1')
>>> MyModel.objects.create(title='The XYZ 2')
>>> MyModel.objects.create(title='XYZ 10')
>>> [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.1.tar.gz (1.8 kB view hashes)

Uploaded Source

Supported by

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