Skip to main content

A Django field that automatically generates random slugs.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

DO NOT USE!

This project is no longer maintained.

It was originally made to replicate the style of URL you find on many websites to obfuscate integer based primary keys. However the implementation relies on expensive database lookups to prevent collisions.

A better/modern alternative to this project would be something using sqids.

django-randomslugfield

Django field that automatically generates random slugs.

e.g. example.com/kEwD58P

Tested with Python 2.7, 3.3+ and Django 1.4+.

Getting it

To install django-randomslugfield:

    $ pip install django-randomslugfield

Install

To enable randomslugfield in your project you need to add it to INSTALLED_APPS in your projects settings.py file:

    INSTALLED_APPS = (
        ...
        'randomslugfield',
        ...
    )

Usage

Import RandomSlugField and use it in your model:

    from django.db import models
    from randomslugfield import RandomSlugField

    class MyModel(models.Model):
        slug = RandomSlugField(length=7)

The length argument is required.

Advanced Usage

By default randomslugfield generates its slug using these characters:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

You can optionally exclude lowercase/uppercase/digits/vowels using exclude_lower=True, exclude_upper=True, exclude_digits=True, exclude_vowels=True.

You cannot exclude all characters.

Example:

    class MyModel(models.Model):
        slug = RandomSlugField(length=7, exclude_lower=True)

The total number of unique slugs is determined by characters^length.

    62^9 = 13,537,086,546,263,552 possible slugs
    62^8 = 218,340,105,584,896 possible slugs
    62^7 = 3,521,614,606,208 possible slugs
    62^6 = 56,800,235,584 possible slugs
    62^5 = 916,132,832 possible slugs

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_randomslugfield-0.3.0.post1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

django_randomslugfield-0.3.0.post1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file django_randomslugfield-0.3.0.post1.tar.gz.

File metadata

File hashes

Hashes for django_randomslugfield-0.3.0.post1.tar.gz
Algorithm Hash digest
SHA256 1056c0c8f863a631864112c06db070e5a6961d502d84982ddd3e21266deb67b7
MD5 66cd4673245462fbdeeddec13c34509e
BLAKE2b-256 d4d5aaebc8e7dacb1a26a6c1e9422c2ad52a8c152c9ae0ba0deb703c0876939f

See more details on using hashes here.

File details

Details for the file django_randomslugfield-0.3.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_randomslugfield-0.3.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 4055447c5fc691fc76bb53e79db614ae9cd599c790ad208d6123a2f853976332
MD5 f75ec15d5b91fda09dbb83cce36d3218
BLAKE2b-256 d426feae8491a3411ee2bea7d81dbbcd37073aaae8ddb7f0a9055eab568ecfdf

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