7

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)   
0

1 Answer 1

19

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.