Reputation: 4576
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", it blanks it out of the slug. Also I tried "before" and the second I hit the E button, it blanked that out too. Is this expected with prepopulated fields or am I doing something wrong?
Models.py
title = models.CharField(max_length=255)
entry = models.TextField()
date_edited = models.DateTimeField(auto_now=True, verbose_name = "Last edited")
date_posted = models.DateTimeField(verbose_name="Post Date")
slug = models.SlugField(max_length=255, unique=True)
Admin.py
prepopulated_fields = {"slug": ("title",)}
Upvotes: 3
Views: 1113
Reputation: 4576
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()
Upvotes: 2
Reputation: 309089
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.
Upvotes: 2