Automatic slug field for Django.
Project description
Automatic slug field for your Django models.
Features
One query to rule them all. No database spam on model save.
Supports all standard “unique_for” field attributes like unique_for_date.
Supports model meta unique_together.
Supports custom “slugify” functions.
How it works
django-slugger provides AutoSlugField which value is automatically generated if it is not filled manually. If the field has any “uniqueness” constraint (unique=True, for example), numerical suffix will be used if necessary to prevent constraint violation.
If generated slug exceeds field max_length, slug value will be cut to fit in. This does not apply to suffixed slugs. Increase max_length attribute value or use custom slug template if you need more space to ensure slug uniqueness.
Installation
pip install django-slugger
Usage
from slugger import AutoSlugField
class AutoSlugModel(models.Model):
title = models.CharField(max_length=255)
slug = AutoSlugField(populate_from='title')
Custom slug template
By default, django-slugger will use Django slugify function (combined with unidecode to handle non-ASCII characters). To use your own function, specify it in slugify argument.
def custom_slugify(value):
return 'custom-%s' % value
class CustomAutoSlugModel(models.Model):
title = models.CharField(max_length=255)
slug = AutoSlugField(populate_from='title', slugify=custom_slugify)
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
Built Distribution
File details
Details for the file django-slugger-1.1.2.tar.gz
.
File metadata
- Download URL: django-slugger-1.1.2.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634fcb6df91319b045f30abe50c6835a4fab12ade5d35616accb83fbd481e096 |
|
MD5 | 957858cbf43d951555fd3c3ed22ec4a6 |
|
BLAKE2b-256 | 1e0210e6b2fc09fd87f34b26829b839a3687479f98614220dac9f8f55505c143 |
File details
Details for the file django_slugger-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: django_slugger-1.1.2-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61059a482774945357924f1fd75f4f0028f54488d5b518d2dd527d967348237c |
|
MD5 | 70521f0815ffa8dbdcd139f5bca91e0c |
|
BLAKE2b-256 | 131a085ef983d0d9cc01d830a39a713ac2f8ba93546ebf8ce8b3c9597ffd2982 |