Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 'prepopulated_fields' not working

Hey I am working through the Practical Django Projects book and I am trying to prepopulate the SlugField but it's not happening.

#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)   
like image 723
bbharadwaj Avatar asked Jan 23 '13 14:01

bbharadwaj


1 Answers

change admin.site.register(Category) to admin.site.register(Category, CategoryAdmin)

like image 112
Emmet B Avatar answered Sep 18 '22 23:09

Emmet B