英文:
To Automatically Add Language to Book instance when Book is selected
问题
我想在每个BookInstance表中显示书籍的语言是如何做到的。请指导我。
其他一切正常。
这是代码:
Modals.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
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论