Last Updated: February 25, 2016
·
1.309K
· r0sk

Slugfield on Django

Want a slug field on your model with some magic and no worries?

class Entry(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField() 

Talking about Django and the baked admin, that's easy peasy:

class AdminEntries(admin.ModelAdmin):
    prepopulated_fields = { 'slug': ['title'] }

And you know, every time you fill the title you will get the slug for free!