自动将语言添加到书籍实例,当选择书籍时。

huangapple go评论62阅读模式
英文:

To Automatically Add Language to Book instance when Book is selected

问题

我想在每个BookInstance表中显示书籍的语言是如何做到的。请指导我。
其他一切正常。

这是代码:

Modals.py

Modals.py

Admin.py

Admin.py

注意:我是Django的新手。

英文:

I want to Show Language of Book In Each BookInstance Table?
How Do i do it. Please Guide me
Everything Else is Working Fine.

Here is the code :-

Modals.py

Modals.py

Admin.py

Admin.py

Note :- i am new to django

答案1

得分: 1

请查看以下翻译:

class AdminBookInstance(admin.ModelAdmin):
    model = BookInstance
    list_display = ('book', 'due_back', 'status', 'cover', 'id', 'language')
    list_filter = ('book', 'due_back', 'status', 'cover', 'id', 'book__language__language_name')
    def language(self, obj):
        data = list(obj.book.language.filter(book=obj.book).values_list("language_name", flat=True))
        return data

admin.site.register(BookInstance, AdminBookInstance)

如果需要更多翻译或有其他问题,请随时告诉我。

英文:

Try this:

class AdminBookInstance(admin.ModelAdmin):
    model = BookInstance
    list_display = ('book' , 'due_back' , 'status' , 'cover' , 'id', 'language')
    list_filter = ('book' , 'due_back' , 'status' , 'cover' , 'id', 'book__language__language_name')
    def language(self, obj):
        data = list(obj.book.language.filter(book=obj.book).values_list("language_name", flat=True))
        return data


admin.site.register(BookInstance, AdminBookInstance)

huangapple
  • 本文由 发表于 2023年4月6日 19:01:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75948755.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定