Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

graphistry/django-autoslugfield

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Automatic slug generation from content

Install

pip install https://github.com/mireq/django-autoslugfield.git

Usage

Settings

INSTALLED_APPS = (
        # ...
        'django_autoslugfield',
)

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.

Advanced usage

AutoSlugField arguments are:

  • reserve_chars - number of characters reserved for suffix
  • title_field - use specific field instread of __str__ method
  • in_respect_to - generate unique slug for specific subset of fields (or not
    unique when in_respect_to contains pk)
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')

About

Automatic slug field for django

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%