justinmayer / django-autoslug

AutoSlugField for Django. Supports (but not does not require) unidecode/pytils for transliteration. Old issue tracker is at Bitbucket: https://bitbucket.org/neithere/django-autoslug/issues

Home Page:https://readthedocs.org/projects/django-autoslug/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Populate with two fields

galileoguzman opened this issue · comments

Hi, I have a question, ¿May I populate AutpSlugField with more than one field? I mean, if I want to generate slug with this model:

class Article(models.Model):
name = models.CharField()
created_at = models.DateField()
slug = AutoSlugField(populate_from=('title', 'created_at'))

This will generate the next slug: 'article-name-2016-08-04'

slug = AutoSlugField(populate_from=lambda instance: "{0}-{1}".format(instance.title, instance.created_at.isocalendar()))

It solves your problem but Django can't generate migration files. So, you need create a separated function instead of lambda function.