Reputation: 1671
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)
Upvotes: 2
Views: 2339
Reputation: 146
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.
Upvotes: 3
Reputation: 40052
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:
Upvotes: 0
Reputation: 15599
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.
Upvotes: 0