Skip to main content

Automatic slug for django

Project description

codecov version downloads license

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.5.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_easy_autoslug-1.0.5-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file django_easy_autoslug-1.0.5.tar.gz.

File metadata

  • Download URL: django_easy_autoslug-1.0.5.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.20

File hashes

Hashes for django_easy_autoslug-1.0.5.tar.gz
Algorithm Hash digest
SHA256 f28a4ad0e1736c59aa0bcf16afdee00400ee28ed70edad3012aace3bcb549dbd
MD5 437435fe024d7e06f4c21bff093f91af
BLAKE2b-256 11c19dc8d4ffa80558893beb9d568fef18a650af17743a3cb31e13369cecb212

See more details on using hashes here.

File details

Details for the file django_easy_autoslug-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for django_easy_autoslug-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cd4cb3e9ca09a60a0aeb364d1d09a55a9b44b10d4ab733757bcde075686ee324
MD5 a481a4e87008a2de48c00ce806c424fb
BLAKE2b-256 9f02289b876562ba1f1041f5b861132ba22a68f9409b0bcc1cbd88a62e301911

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page