A
A
Animkim2016-05-12 17:54:21
Django
Animkim, 2016-05-12 17:54:21

Signal, where is the error?

from django.db.models.signals import post_save

class Category(models.Model):
    parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
    title = models.CharField(max_length=50)
    slug = models.SlugField(max_length=70, blank=True)

def set_caregory_slug(sender, instance, *args, **kwargs):
    from pytils import translit
    instance.slug = translit.slugify(instance.title.strip())

post_save.connect(set_caregory_slug, sender=Category)

In the shell console, everything works, the signal also works, but for some reason does not record the slug. Do I see an error in my code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2016-05-12
@Animkim

It would be more logical to use the pre_save signal

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question