在哪里可以修改第三方应用的管理视图代码? [英] Where do I modify the admin view code for a 3rd party app?
本文介绍了在哪里可以修改第三方应用的管理视图代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
但是我想为第三方应用程序中的其中一个模型定制管理视图。
定制不只是更改
change_list.html
模板,即我需要添加代码来与外部webservice等进行交流。 但是,我不想修改第三方应用程序。相反,我想覆盖它。
如何覆盖来自第三方应用程序的模型的 ModelAdmin
?
解决方案
这应该让你开始:
from django.contrib import admin
from thirdpartyapp .models import ThirdPartyModel
from thirdpartyapp.admin import ThirdPartyAdmin
class CustomThirdPartyAdmin(ThirdPartyAdmin):
pass
admin.site.unregister (ThirdPartyModel)
admin.site.register(ThirdPartyModel,CustomThirdPartyAdmin)
我经常使用定制UserAdmin ,如此答案所示。
I am using a 3rd party app in my django webapp.
But I want to customize the admin view for one of the models in the 3rd party app.
The customization is more than changing the change_list.html
template i.e. I will need to add code to talk to an external webservice etc.
However, I don't want to modify the 3rd party app. Instead I want to override it.
How I override the ModelAdmin
for a model that comes from a 3rd party app ?
解决方案
This should get you started:
from django.contrib import admin
from thirdpartyapp.models import ThirdPartyModel
from thirdpartyapp.admin import ThirdPartyAdmin
class CustomThirdPartyAdmin(ThirdPartyAdmin):
pass
admin.site.unregister(ThirdPartyModel)
admin.site.register(ThirdPartyModel, CustomThirdPartyAdmin)
I use this often to customize the UserAdmin as shown in this answer.
这篇关于在哪里可以修改第三方应用的管理视图代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文