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
Built Distribution
File details
Details for the file django_easy_autoslug-1.0.4.tar.gz
.
File metadata
- Download URL: django_easy_autoslug-1.0.4.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1201e2a5285147193c45377d276c4f13ce6f482291bc75ecc45c14146f370666 |
|
MD5 | c4d0094133261feb15279fca94385118 |
|
BLAKE2b-256 | 8949cd7cc9cdba51d3d2b24f8efa182f4ac70bd7b69afbece1ebccd59aa42139 |
File details
Details for the file django_easy_autoslug-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: django_easy_autoslug-1.0.4-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b631d8a7151742307abf7b78a2ec5744252753a1f797d78f1e99a679cf20f6 |
|
MD5 | 2fa165607a5ca373b8114e45dae3c6ca |
|
BLAKE2b-256 | 5a5bba58de8fa04e12f43c2c87d7694e92476dc51f3ba3313e4d5abe4eaeeb6c |