Django'prepopulated_fields'无效

时间:2013-01-23 14:46:36

标签: django django-admin

嘿我正在阅读Practical Django Projects的书,我正在尝试预先填充SlugField,但它没有发生。

#models.py
from django.db import models

class Category (models.Model):
    title = models.CharField(max_length=250)
    slug = models.SlugField (unique=True)
    description = models.TextField()

    class Meta:
        verbose_name_plural = "Categories"

    def __unicode__(self):
        return self.title
#admin.py
from django.contrib import admin
from coltrane.models import Category

class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}

admin.site.register(Category)   

1 个答案:

答案 0 :(得分:15)

admin.site.register(Category)更改为admin.site.register(Category, CategoryAdmin)