Skip to content

Instantly share code, notes, and snippets.

@dokterbob
dokterbob / autoslug.py
Created February 15, 2011 18:46
Mixins for automatically setting (unique) slugs for Django models -- also using values from inline classes.
from django.template.defaultfilters import slugify
class AutoSlugMixin(object):
"""
Automatically set slug to slugified version of the name if left empty.
Use this as follows::
class MyModel(AutoSlugMixin, models.Model):
def save(self):
super(MyModel, self).save()