我在Django中创建了两个模型,其中一个模型用于多对多字段,我想要的是在管理多对多字段中添加内容时,尽管应该将其显示在弹出窗口中内联可编辑。
我已经使用表格内联进行了尝试,但这不起作用。
from django.db import models
# Create your models here.
class Author(models.Model):
name = models.CharField(max_length=100)
class Book(models.Model):
author = models.ManyToManyField(Author,through=Test1.tests2.through)
title = models.CharField(max_length=100)
from django.contrib import admin
from basic_app.models import Author,Book
# Register your models here.
class BookInline(admin.TabularInline):
model = Book.author.through
extra = 1
class AuthorAdmin(admin.ModelAdmin):
inlines = [
BookInline,
]
admin.site.register(Book)
admin.site.register(Author,AuthorAdmin)