Skip to content
Newer
Older
100644 88 lines (54 sloc) 1.99 KB
c6919ce @mkrjhnsn changed readme to rst
authored
1 django-randomslugfield
2 ======================
3
4 .. image:: https://travis-ci.org/mkrjhnsn/django-randomslugfield.svg?branch=master
4eeb5e7 @mkrjhnsn fixed readme formatting
authored
5 :target: https://travis-ci.org/mkrjhnsn/django-randomslugfield
873de8e @mkrjhnsn updated badge links
authored
6 .. image:: https://pypip.in/version/django-randomslugfield/badge.svg
7 :target: https://pypi.python.org/pypi/django-randomslugfield/
8 .. image:: https://pypip.in/download/django-randomslugfield/badge.svg
9 :target: https://pypi.python.org/pypi/django-randomslugfield/
c6919ce @mkrjhnsn changed readme to rst
authored
10
11 Django field that automatically generates random slugs.
12
13 e.g. example.com/kEwD58P
14
15 Tested with Python 2.7, 3.3+ and Django 1.4+.
16
acea147 @mkrjhnsn changed readme formatting
authored
17
c6919ce @mkrjhnsn changed readme to rst
authored
18 Getting it
19 ----------
20
acea147 @mkrjhnsn changed readme formatting
authored
21 To install django-randomslugfield:
c6919ce @mkrjhnsn changed readme to rst
authored
22
23 .. code:: bash
24
25 $ pip install django-randomslugfield
26
acea147 @mkrjhnsn changed readme formatting
authored
27
c6919ce @mkrjhnsn changed readme to rst
authored
28 Install
29 -------
30
31 To enable ``randomslugfield`` in your project you need to add it to
32 ``INSTALLED_APPS`` in your projects ``settings.py`` file:
33
34 .. code:: python
35
36 INSTALLED_APPS = (
4eeb5e7 @mkrjhnsn fixed readme formatting
authored
37 ...
38 'randomslugfield',
39 ...
c6919ce @mkrjhnsn changed readme to rst
authored
40 )
41
acea147 @mkrjhnsn changed readme formatting
authored
42
c6919ce @mkrjhnsn changed readme to rst
authored
43 Usage
44 -----
45
46 Import ``RandomSlugField`` and use it in your model:
47
48 .. code:: python
49
50 from django.db import models
51 from randomslugfield import RandomSlugField
52
53 class MyModel(models.Model):
54 slug = RandomSlugField(length=7)
55
56 The ``length`` argument is required.
57
acea147 @mkrjhnsn changed readme formatting
authored
58
c6919ce @mkrjhnsn changed readme to rst
authored
59 Advanced Usage
60 --------------
61
62 By default randomslugfield generates its slug using these characters:
63
64 ``abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789``
65
66 You can optionally exclude lowercase/uppercase/digits/vowels using
67 ``exclude_lower=True``, ``exclude_upper=True``, ``exclude_digits=True``,
68 ``exclude_vowels=True``.
69
70 You cannot exclude all characters.
71
72 Example:
73
74 .. code:: python
75
76 class MyModel(models.Model):
77 slug = RandomSlugField(length=7, exclude_lower=True)
78
79 The total number of unique slugs is determined by ``characters^length``.
80
81 ::
82
83 62^9 = 13,537,086,546,263,552 possible slugs
84 62^8 = 218,340,105,584,896 possible slugs
85 62^7 = 3,521,614,606,208 possible slugs
86 62^6 = 56,800,235,584 possible slugs
87 62^5 = 916,132,832 possible slugs
Something went wrong with that request. Please try again.