Skip to content

TvrtkoM/django-randomslug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django RandomSlugField

A simple model field providing random & unique slug field for your django models

Installation

python setup.py install

or:

pip install django-randomslug

Append 'randomslug' to your INSTALLED_APPS setting

Usage

Create a django model like usual and add a RandomSlugField:

# models.py
from randomslug.models import RandomSlugField

class ModelWithSlug(models.Model):
    slug = RandomSlugField()

The slug value will now be randomized each when the model has to be saved to database for the first time. If the same value already exist the value will get suffix of the pattern "_%d" % number where number is positive integer, so each slug will be unique.

RandomSlugField accepts slug_length option which represents the number of randomized characters in slug (excluding number suffix) e.g. slugs 'xc-45' & 'xf987_23' are both of the slug_length 5

About

reusable Django application providing the custom RandomSlugField model field

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages