从XML生成Django模型 [英] Generating django models from xml

查看:106
本文介绍了从XML生成Django模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件。

是否可以通过XML文件生成Django模型?还是应该对它进行硬编码?

Is there a way to generate Django models from the XML file? or should I hardcode it?

我已经在网上搜索了好几个小时,所以我猜 rest frame work和 django Adaptors可以完成这项工作,但是我不确定如何去做。

I've been searching online for hours, and I guess "rest frame work" and "django adaptors" do the job, but I am not so sure how to go about doing that.

如果有人熟悉Django和XML,将不胜感激。

If there is anyone familiar with Django and XML, any help will be appreciated.

谢谢。

推荐答案

这里有一个演讲,其中包含将XML文件作为类导入的教程:

Here a talk which contains a tutorial to import an xml file as class:

http://youtu.be/sPiWg5jSoZI?t = 2h30s

如果您使用py3k进行运行,(我认为此出色且有趣的演示的特定演示与python 2.6及更高版本兼容),我将获得如何用models.xml替换models.py的想法。

If you run with py3k, (I think this particular demo of this awesome and funny demonstration is compatible with python 2.6 and upper), you'll get the idea on how to replace your models.py by a models.xml. You'll have to adapt it to your xml format by yourself.

(至少需要从2h到2h32m左右)

(you'll need to look at least from around 2h to 2h32m)

这个演讲解释了一种有趣的方式,演讲者似乎并不相信这是一个好主意。
如果您想从WSDL生成api模型,我建议您仍然使用硬代码制作表模型,因为我想数据库不是动态的。只需使方法/静态方法将api模型转换为数据库模型即可。

This talk explain a fun way to do it, the speaker doesn't seem convinced that it's a great idea. If you want to generate api models from WSDL, I would suggest you to still make your tables models in hard code as your database isn't dynamic I suppose. Simply make methods/static methods to translate api models to db models.

这篇关于从XML生成Django模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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