#30538: Inconsistent slug generation behaviour of slugify() and prepopulated 
in Django Admin
               Reporter:             |          Owner:  nobody
  nomenklature                       |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:             |        Version:  2.2
  Uncategorized                      |       Keywords:  slugify
               Severity:  Normal     |  prepopulated fields
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
 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
 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
 prepopulated_fields] to generate a slug. The relevant javascript function
 seems to be found

 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:

 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

         // Remove English words only if the string contains ASCII
         // characters.
         if (!hasUnicodeChars) {
             var removeList = [
                 "a", "an", "as", "at", "before", "but", "by", "for",
                 "is", "in", "into", "like", "of", "off", "on", "onto",
                 "since", "than", "the", "this", "that", "to", "up", "via",
             var r = new RegExp('\\b(' + removeList.join('|') + ')\\b',
             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
 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?

Ticket URL: <https://code.djangoproject.com/ticket/30538>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to