﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30538	Inconsistent slug generation behaviour of slugify() and prepopulated fields in Django Admin.	Loo Zheng Yuan	nobody	"Hi everyone. I wanted to highlight an inconsistent slug generation behaviour that I noticed.

So, for generating slugs, there are two ways I can go about doing it. One way is by using the [https://github.com/django/django/blob/dffa3e1992562ba60512d96d1eb5859ffff2ceb5/django/utils/text.py#L393 django.utils.text.slugify()] function to create a slug. This behaviour allows us to create a default for a model field by modifying the save() function, etc. Another way, if you are using Model Admin, is by using the [https://docs.djangoproject.com/en/2.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields prepopulated_fields] to generate a slug. The relevant javascript function seems to be found [https://github.com/django/django/blob/dffa3e1992562ba60512d96d1eb5859ffff2ceb5/django/contrib/admin/static/admin/js/urlify.js#L161 here].

Interestingly, and pretty obviously after viewing the differences between the two codes, they result in slightly different slugs. For a string like `How To Maintain Coke Diet` will have the following inconsistencies:

Via [https://github.com/django/django/blob/dffa3e1992562ba60512d96d1eb5859ffff2ceb5/django/utils/text.py#L393 django.utils.text.slugify()]: `how-to-maintain-coke-diet`
Via prepopulated_fields: `how-maintain-coke-diet`

On closer analysis, it seems that this was the case because of the following code in [https://github.com/django/django/blob/dffa3e1992562ba60512d96d1eb5859ffff2ceb5/django/contrib/admin/static/admin/js/urlify.js#L161 django/contrib/admin/static/admin/js/urlify.js]:

{{{
        // Remove English words only if the string contains ASCII (English)
        // characters.
        if (!hasUnicodeChars) {
            var removeList = [
                ""a"", ""an"", ""as"", ""at"", ""before"", ""but"", ""by"", ""for"", ""from"",
                ""is"", ""in"", ""into"", ""like"", ""of"", ""off"", ""on"", ""onto"", ""per"",
                ""since"", ""than"", ""the"", ""this"", ""that"", ""to"", ""up"", ""via"",
                ""with""
            ];
            var r = new RegExp('\\b(' + removeList.join('|') + ')\\b', 'gi');
            s = s.replace(r, '');
        }
}}}

With that, I recognise that there may be reasons accounting for the inconsistencies. One could also argue that I can just stick to using the [https://github.com/django/django/blob/dffa3e1992562ba60512d96d1eb5859ffff2ceb5/django/utils/text.py#L393 django.utils.text.slugify()] function, but I value the ability to prepopulate slug fields from Django Admin (of course with a more standardised behaviour). 

Perhaps someone can weigh in on this and see if we can or should standardise the implementation of both?
"	Bug	closed	Utilities	dev	Normal	wontfix	slugify prepopulated fields		Unreviewed	0	0	0	0	0	0
