views:

38

answers:

3

Since Django 1.2.1 'prepopulated_fields' won't prepopulate in the admin.

prepopulated_fields = {'slug': ('title',)} doesn't seem to work since uploading to a Django 1.2.1 server after developing on a 1.1.1.

What changed?

I read http://code.djangoproject.com/wiki/NewformsAdminBranch#Changedprepopulate_fromtobedefinedintheAdminclassnotdatabasefieldclasses but didn't find a way to fix it, my code seems good.

Ideas? Code:

class Data(models.Model):
    title = models.CharField(max_length=50)
    slug = models.SlugField(max_length=50, unique=True, help_text='Unique value for product page URL, created from name.')


class DataAdmin(admin.ModelAdmin):
    list_display = ('title', 'user', 'category')
    list_filter = ('user', 'category')
    ordering = ('title',)
    search_fields = ('title',)
    prepopulated_fields = {'slug': ('title',)}  
admin.site.register(Data, DataAdmin)
A: 

Did you read the current documentation for prepulated_fields ?

It would help if you showed your code, but you just place it under your Admin class, it's a pretty straight forward setup.

Bartek
Nothing new there, but like I said it works on 1.1.1 not 1.2.1.Also added code per your request, thanks.
pythondjango
I suggest seeing Gabriel's answer .. that has to be it, unless you're running trunk and the function was broken on a few revisions.
Bartek
A: 

I can say with certainty that prepopulated_fields still works as indicated in the docs. Your code looks sound, but here are some possible problems I can think of:

  1. Javascript is disabled and/or your admin media links are broken.
  2. You've got a typo somewhere in the names of your fields.
  3. You have something cached in your browser that is preventing the javascript from working correctly.
Gabriel Hurley
3 different browsers, full refreshes, cleared caches. I've stared at this code for hours and can't find anything. Also everything in the admin looks good, no dead links/images.
pythondjango
A: 

It happened to me exactly when upgrading from django 1.1.1 to 1.2.1. It is because the media/admin directory it has changed, before it was something like that: media/admin/js/admin and now is: admin/media/js/admin. What I did was to change in settings ADMIN_MEDIA_PREFIX = '/media/admin/'

To be sure when you are in your admin page, the one that does not prepopulate, run firebug and check from where that page is trying to fetch the js files. You will see that there is a discrepancy between that location and the actual location of those js files in Django 1.2.1.

OK so this has been resolved! It was a server-side issue. The server company has a few different versions of Django available and the installation I was using was missing the proper .js files.
pythondjango