简体   繁体   English

Django在管理员加载时自动填充

[英]Django auto-populate on admin load

I am building a simple Django project to manage a bunch of phone numbers and call logs that we have in Twilio and other cloud telephony providers. 我正在构建一个简单的Django项目,以管理Twilio和其他云电话提供商中拥有的大量电话号码和通话记录。 I would like to keep in Django a list of the phone numbers that we have in Twilio. 我想在Django中保留我们在Twilio中拥有的电话号码列表。 I am easily able to query Twilio's API to get our current numbers, and it seems quite simple to use this list to populate my Django DB. 我可以很容易地查询Twilio的API来获取当前的数字,并且使用此列表填充Django DB似乎很简单。

However, to make sure the list in Django is kept in sync with Twilio, I would like to call Twilio's API and update the list of numbers in Django every time a user loads the list of phone numbers in the admin. 但是,为确保Django中的列表与Twilio保持同步,我想调用Twilio的API并在用户每次在管理员中加载电话号码列表时更新Django中的数字列表。

Question: how do I get Django to run this call every time the list of numbers loads in the admin? 问题:每次让数字列表加载到管理员中时,我如何让Django运行此调用?

You could use a custom Django admin class and redefine eg ModelAdmin.get_queryset to fetch the new data, then return the QuerySet: 您可以使用自定义Django管理类并重新定义例如ModelAdmin.get_queryset来获取新数据,然后返回QuerySet:

class MyModelAdmin(admin.ModelAdmin):
    def get_queryset(self, request):
        update_data_from_api()
        return = super(MyModelAdmin, self).get_queryset(request)

一种方法是将自定义admin操作添加到电话列表的ModelAdmin中以进行上载过程,然后在此处启动API提取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM