如何外部填充Django模型? [英] How to externally populate a Django model?

查看:117
本文介绍了如何外部填充Django模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从外部来源将数据填充到Django模型中的最佳方法是什么?

What is the best idea to fill up data into a Django model from an external source?

例如。我有一个模型运行,并运行一个XML文件中的数据,每周更改。

E.g. I have a model Run, and runs data in an XML file, which changes weekly.

我应该创建一个视图,并从卷曲cronjob调用该视图URL有利于数据可以随时读取,不仅可以在cronjob运行时使用),还可以创建一个python脚本,并将该脚本安装为cron(在执行脚本之前使用DJANGO _SETTINGS _MODULE变量设置)?

Should I create a view and call that view URL from a curl cronjob (with the advantage that that data can be read anytime, not only when the cronjob runs), or create a python script and install that script as a cron (with DJANGO _SETTINGS _MODULE variable setup before executing the script)?

推荐答案

在项目环境中做一些类似维护的工作有很好的方法 - 写一个 custom manage.py命令。它需要所有的环境配置和其他东西,让你专注于具体的任务。

There is excellent way to do some maintenance-like jobs in project environment- write a custom manage.py command. It takes all environment configuration and other stuff allows you to concentrate on concrete task.

当然,直接由cron调用它。

And of course call it directly by cron.

这篇关于如何外部填充Django模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆