Usage

This section contains information, including examples, about how to use django-primary-slug in your existing Django projects or applications.

The EnhancedImageField

class primary_slug.fields.PrimarySlugField(*args, **kwargs)

This model field is an enhanced version of Django’s SlugField.

django-primary-slug provides an enhanced version of the default Django’s SlugField, which supports:

  • Custom slugify function.
  • Custom list of valid characters.

The PrimarySlugField derives from the default SlugField and thus all attributes and methods of the default SlugField are inherited.

In addition to the default arguments, the PrimarySlugField also supports the following:

populate_from
A string or callable that returns the initial value to be slugified. If this is not set, then the slug field is not populated automatically. Also, if the slug field is set by the user, then it is not auto- populated.
slugify
A callable python object which slugifies the value retrieved from the populate_from field. If this is not set, then the function defined in the PRIMARY_SLUG_SLUGIFY_FUNC setting is used.

The following code snippet illustrates how to use the PrimarySlugField:

from django.db import models
from primary_slug.fields import PrimarySlugField

class MyModel(models.Model):
    title = models.CharField(max_length=160)
    slug = PrimarySlugField(populate_from='title', max_length=160)

Table Of Contents

Previous topic

Configuration

Next topic

Frequently Asked Questions

This Page