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.0.tar.gz
(13.8 kB
view hashes)
Built Distribution
Close
Hashes for django_easy_autoslug-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf8c9ef2f4419cd91bc1e8e8538c869e8bb03c003442811a0ec721ff2d9d9505 |
|
MD5 | a1426dd94f911e35913137ad28ee390f |
|
BLAKE2b-256 | d4c39dba0eb65c759e739047415a40792f3afd43f9bc51eeff1f9b5b687c6c30 |
Close
Hashes for django_easy_autoslug-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d992ac9bc501d140c93c0ad906a7084a0c029531d2dfc93a5edd8a1f8fc2b43d |
|
MD5 | 2d48a1b1736425a0cfff103a6d93b1d3 |
|
BLAKE2b-256 | 85cc4d3d7196a7fa72052a0536dfd8f7a64cccb9b71856cda977aa25cc58f299 |