我是python / django的新手。
我正在使用Django 1.11,Python 3.5.2和Oracle 11g r2
我想在oracle数据库中为TABLE1创建Django模型
我的TABLE1有4个字段:
ID(TYPE:NUMBER)
名称(类型:VARCHAR2)
姓氏(类型:VARCHAR2)
INFO(类型:XMLTYPE)
这是xml字段的格式:
<?xml version = '1.0' encoding = 'UTF-8'?><extrainfo>
<info>
<movie>Titanic</movie>
<sport>Tennis</sport>
</info>
<info>
<movie>Troy</movie>
<sport>Soccer</sport>
</info>
</extrainfo>
我正在为table1创建django模型,但是我不知道如何使用django读取db中的xml字段。
这是我的模特
class Table1(models.Model):
id = models.IntegerField(primary_key=True)
name = models.TextField(blank=True)
lastname = models.TextField(blank=True)
info = (I dont know what to write here to read the xmltype in db)
class Meta:
managed = False
db_table = 'TABLE1'
我该怎么办?
最好的方法是什么?
我需要获取xmltype信息。
请帮助我,我被困住了。
谢谢。
最佳答案
您尝试过https://github.com/theatlantic/django-xml吗?我已经尝试过了,但是似乎没有保存到数据库。此外,您可以将TextField用作xml的容器,并使用lxml解析器。