Skip to main content

a smart slug field for your models

Project description

slug fields for the lazy

Examples

There are exhausting examples in the tests, but here’s the quick rundown:

from django.db import models
from smart_slug.fields import SmartSlugField

class Simple(models.Model):
    slug = SmartSlugField(max_length=5, underscores=False)

class Complex(models.Model):
    title = models.CharField(max_length=100)
    slug = SmartSlugField(
        source_field='title',
        date_field='pub_date',
        split_on_words=True,
        max_length=10)
    pub_date = models.DateTimeField(auto_now=True)

>>> s1 = Simple.objects.create(slug='simple')
>>> s1.slug
simpl

>>> s2 = Simple.objects.create(slug='simple')
>>> s2.slug
sim-1

>>> s3 = Simple.objects.create(slug='simple')
>>> s3.slug
sim-2

>>> c1 = Complex.objects.create(title='complex example')
>>> c1.slug
complex

>>> c2 = Complex.objects.create(title='complex example')
>>> c2.slug
complex_

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-smart-slug-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file django-smart-slug-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-smart-slug-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cf6f1c0b4e5bf6a019945d488d6b10763af56be3bd6961bc36925bcc658b05c8
MD5 8aa1bf6ef7177941fcf6bac6c255b69e
BLAKE2b-256 19458ff54b8801e2070b4acc6d0226d676eb3f51f093b686f598474c8cdf06ae

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page