Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django model with XMLField

I'm new to python/django.

I'm using django 1.11, python 3.5.2 and Oracle 11g r2

I want to create a django model for the TABLE1 in oracle database

my TABLE1 has 4 fields:

ID (TYPE: NUMBER)

NAME (TYPE: VARCHAR2)

LASTNAME (TYPE: VARCHAR2)

INFO (TYPE: XMLTYPE)

This is the format of the xml field:

<?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>

I'm creating a django model for table1, but I don't know how to read the xml field in db using django.

This is my model

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' 

What Should I do? What is the best way to do it?

I need to get the xmltype information.

Please help me, I'm stuck.

Thanks.

like image 393
Angel Pineda Avatar asked Sep 19 '25 01:09

Angel Pineda


1 Answers

did you try https://github.com/theatlantic/django-xml? I have tried this, but it seems not saving to database. Furthermore, you can use TextField as a container of xml and use lxml parser.

like image 95
Erdenezul Avatar answered Sep 20 '25 16:09

Erdenezul