Automatic slug for django
Project description
This package is used to automatically create unique slugs.
Install
pip install django-easy-autoslug
Usage
Basic example
# models.py
from django_autoslugfield import AutoSlugField
class Item(models.Model):
title = models.CharField(max_length=255)
slug = AutoSlugField(max_length=255, unique=True)
Slug is created from __str__ method. If another object with same slug already exists slug will be suffixed with number -2, -3 …
Advanced usage
AutoSlugField arguments are:
reserve_chars - number of characters reserved for suffix (including sparator -)
title_field - use specific field instread of __str__ method
in_respect_to - generate unique slug for specific subset of fields
Following code can create same slug for another month / year.
from django_autoslugfield import AutoSlugField
class Blog(models.Model):
title = models.CharField(max_length=255)
slug = AutoSlugField(filter_fields=('year', 'month'), max_length=255)
year = models.IntegerField()
month = models.IntegerField()
class Meta:
unique_together = ('slug', 'year', 'month')
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_easy_autoslug-1.0.3.tar.gz
(14.2 kB
view hashes)
Built Distribution
Close
Hashes for django_easy_autoslug-1.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138c3affa6c6ae643cba2151927ca3098466f7b813bc82744206338f1f7939b3 |
|
MD5 | 6a65307ff973286f37b78e3b44e1398f |
|
BLAKE2b-256 | a3d46f1b838993c1dfba5ff5ba8e0dada847588b125606c5602cb63c545ddbfb |
Close
Hashes for django_easy_autoslug-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd79d05b92d847a23f3e369b13ec4fa9f3ba1eca20c50e58bbb988b5e86aa9d2 |
|
MD5 | 48ff771de64beb515166942b9b7a16a4 |
|
BLAKE2b-256 | 1931bbd9c2946a0cd8fc4788268b85f6f6ff17f63ad0fd5f0d5cf3c2962020e5 |