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.2.tar.gz
(14.1 kB
view hashes)
Built Distribution
Close
Hashes for django_easy_autoslug-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2326d748d96997876aebef4c20e9461be1ece6c9b86427268ef33206e95d698 |
|
MD5 | f411983c152de473db24546766022bca |
|
BLAKE2b-256 | cf7c71202c28c311e8fbcb7544891dfc6642552ad6d1b344ffa52a64029faa7b |
Close
Hashes for django_easy_autoslug-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3887f3ea1ddeda073ea512920ab93b22c110e8f7e598a36bdbabfaf0f2d951a5 |
|
MD5 | 1fdda87f97e48244cd55b302c7dc0aba |
|
BLAKE2b-256 | 33965500ca28747d1c1eea850378ee0a26b20ebbdd63e9da90ed660b58837e55 |