2011-08-16 70 views
1

下面有一個這樣的模型,在管理面板創建/編輯Author實例時,如何要求添加至少一本書?Django admin內嵌模型管理員需要

#models.py 
class Author(models.Model): 
    name = models.CharField(max_length=100) 

class Book(models.Model): 
    author = models.ForeignKey(Author) 
    title = models.CharField(max_length=100) 

#admin.py 
class BookInline(admin.TabularInline): 
    model = Book 

class AuthorAdmin(admin.ModelAdmin): 
    inlines = [ 
     BookInline, 
    ] 

回答