且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过内联显示在Django Admin中编辑/添加外键对象

更新时间:2023-02-08 19:27:09

django_reverse_admin 是django模块,用于解决需要内联的问题,其中关系是错误的方向。

django_reverse_admin is a django module to solve this problem of needing inlines where the relationships are the 'wrong' direction.

您需要将其添加到requirements.txt中,然后将其导入:

You'll need to add it to your requirements.txt and then import it:

admin.py

from django_reverse_admin import ReverseModelAdmin

class Complete_Book(ReverseModelAdmin):
    # usual admin stuff goes here
    inline_type = 'tabular'  # or could be 'stacked'
    inline_reverse = ['book']  # could do [('book', {'fields': ['title', 'authors'})] if you only wanted to show certain fields in the create admin

admin.site.register(Book, Complete_Book)