#33472: Function django.utils.text.slugify don't work when used in model's Save
method (and I'm not sure it working elsewhere)
-------------------------------------+-------------------------------------
               Reporter:  Vitalii    |          Owner:  nobody
  Khrystiuk                          |
                   Type:  Bug        |         Status:  new
              Component:  Utilities  |        Version:  4.0
               Severity:  Normal     |       Keywords:  slugify, utils
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 This is code in my models.py I was using:


 {{{
 from django.db import models
 from django.utils import timezone
 from markdownx.models import MarkdownxField
 from .utils import markdownify
 from django.contrib.auth.models import User
 from django.dispatch import receiver
 from django.utils.text import slugify

 STATUS = (
         (0,"Draft"),
         (1,"Publish")
 )


 class Blog(models.Model):
     title = models.CharField(max_length=200, unique=True)
     slug = models.SlugField(max_length=200, unique=True,
 allow_unicode=False)
     date = models.DateTimeField(auto_now_add=True)
     description = MarkdownxField()
     date_updated = models.DateTimeField(auto_now=True)
     author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
     status = models.IntegerField(choices=STATUS, default=0)

     class Meta:
         ordering = ['-date']

     def __str__(self):
         return self.title

     def save(self, *args, **kwargs):
             self.slug = slugify(self.title)
             super().save(*args, **kwargs)

     def formatted_markdown(self):
         return markdownify(self.description)
 }}}

 When model is saved, slug field is just empty.

 I've checked if this code is working with "python-slugify" package, and it
 works, creating a valid slug, so issue is definitely in Django slugify
 function.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33472>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.671930a7f2af49132b162f5586bd0163%40djangoproject.com.

Reply via email to