例如,我有这个模型
# models.py
from django.db import models
class Category(models.Model):
title = models.CharField(max_length=60)
class CategoryDescription(models.Model)
category = models.ForeignKey(Category)
description = models.CharField(max_length=120)
class Image(models.Model):
category = models.ForeignKey(Category)
description = models.ForeignKey(CategoryDescription)
image = models.ImageField()
我有这个管理员初始文件
# admin.py
from django.contrib import admin
from .models import Category, CategoryDescription, Image
class CategoryDescriptionInline(admin.TabularInline):
model = CategoryDescription
class CategoryAdmin(admin.ModelAdmin):
inlines = (CategoryDescriptionInline,)
class ImageAdmin(admin.ModelAdmin):
pass
admin.site.register(Category, CategoryAdmin)
admin.site.register(Image, ImageAdmin)
我想在管理员中创建新图像,我创建新类别,使用从选择输入右侧放置的plus
然后,我想选择图像描述,但我不能这样做,因为它没有被加载
在这种情况下,您可能会为我推荐什么?感谢
答案 0 :(得分:0)
为CategoryDescription注册ModelAdmin,例如:
admin.site.register(CategoryDescription)