Skip to content Skip to sidebar Skip to footer

Django Prepopulated Fields With Two/three Letter Words

In my admin.py file I am trying to use Prepopulated_fields to auto slug a title. It seems to have problems with short two letter words however. When I type in 'Is', 'the' or 'to',

Solution 1:

Like @Alasdair said in his answer, there are words that get ignored when you use prepoulated_fields. Instead of overriding the js file that handles those words I turned the slug field from the title in the save_model.

def save_model(self, request, obj, form, change):        
    if not change:
        obj.slug = slugify(('%s') % obj.title)
    obj.save()

Solution 2:

You are using the prepopulated_fields option correctly. If you look at the urlify.js script included in the django admin app, you can see there's a list of words which are ignored.

I'm not aware of an easy way to modify the behaviour besides editing the file itself, which isn't ideal.

Post a Comment for "Django Prepopulated Fields With Two/three Letter Words"