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.1.tar.gz
(14.1 kB
view hashes)
Built Distribution
Close
Hashes for django_easy_autoslug-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d94516e7581b0f6d1be9884f9b50dc8f1cce1af58ad14b0fcc58350972f66f9 |
|
MD5 | 9cb120ed6fb922dd94d8fef15f125183 |
|
BLAKE2b-256 | 60c34d5bc90373ed08fbe8c601e8dcc33522620de757d57d061e7ce7eed7372f |
Close
Hashes for django_easy_autoslug-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26372dca032010b9283e1c796d33a6978a189c014b357430fe64185c6a3dd534 |
|
MD5 | 35f01e182485716aa1dd6f133ce52c52 |
|
BLAKE2b-256 | 1eb61c46fafdfbeb30834274e45fb0b5e4783440aacc29098a959349a0bc632e |