2017-07-01 55 views
1

我是python/django的新手。使用XMLField的Django模型

我使用Django 1.11,蟒蛇3.5.2和Oracle 11g R2

我想创建Oracle数据库为TABLE1一个Django模型

我TABLE1有4个领域:

ID(类型:Number)

名(类型:VARCHAR2)

LASTNAME(TYPE:VARCHAR2)

信息(类型: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> 

我创建表1 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信息。

请帮我,我卡住了。

谢谢。

回答