gpt4 book ai didi

Django 'prepopulated_fields' 不工作

转载 作者:行者123 更新时间:2023-12-04 13:20:03 24 4
gpt4 key购买 nike

嘿,我正在阅读 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)

最佳答案

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

关于Django 'prepopulated_fields' 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14482418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com