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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_randomslugfield-0.3.0.post1.tar.gz.
File metadata
- Download URL: django_randomslugfield-0.3.0.post1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1056c0c8f863a631864112c06db070e5a6961d502d84982ddd3e21266deb67b7
|
|
| MD5 |
66cd4673245462fbdeeddec13c34509e
|
|
| BLAKE2b-256 |
d4d5aaebc8e7dacb1a26a6c1e9422c2ad52a8c152c9ae0ba0deb703c0876939f
|
File details
Details for the file django_randomslugfield-0.3.0.post1-py3-none-any.whl.
File metadata
- Download URL: django_randomslugfield-0.3.0.post1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4055447c5fc691fc76bb53e79db614ae9cd599c790ad208d6123a2f853976332
|
|
| MD5 |
f75ec15d5b91fda09dbb83cce36d3218
|
|
| BLAKE2b-256 |
d426feae8491a3411ee2bea7d81dbbcd37073aaae8ddb7f0a9055eab568ecfdf
|