[Django] #33472: Function django.utils.text.slugify don't work when used in model's Save method (and I'm not sure it working elsewhere)

7 views
Skip to first unread message

Django

unread,
Jan 29, 2022, 1:09:41 PM1/29/22
to django-...@googlegroups.com
#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.

Django

unread,
Jan 29, 2022, 2:22:05 PM1/29/22
to django-...@googlegroups.com
#33472: slugify() don't work when used in model's save() method.
-----------------------------------+--------------------------------------
Reporter: Vitalii Khrystiuk | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: 4.0
Severity: Normal | Resolution: worksforme
Keywords: slugify, utils | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => worksforme


Comment:

It works for me, I cannot reproduce your issue with described models.

--
Ticket URL: <https://code.djangoproject.com/ticket/33472#comment:1>

Reply all
Reply to author
Forward
0 new messages