Note that there are some explanatory texts on larger screens.

plurals
  1. POxml parsing using 2 tables
    primarykey
    data
    text
    <p>I written a function to save the data in xml file to database.I am using two models ,see the below.</p> <p>models.py </p> <pre><code>class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() age = models.IntegerField() class Book(models.Model): book_id=models.AutoField(primary_key=True,unique=True) book_name=models.CharField(max_length=30) publisher_name=models.CharField(max_length=40) author=models.ForeignKey(Author) </code></pre> <p>my .xml file is</p> <pre><code> &lt;book&gt; &lt;book_id&gt;101&lt;/book_id&gt; &lt;book_name&gt;Python&lt;/book_name&gt; &lt;publisher_name&gt;Maxwell&lt;/publisher_name&gt; &lt;author_id&gt;1002&lt;/author_id&gt; &lt;first_name&gt;John&lt;/first_name&gt; &lt;last_name&gt;Dezosa&lt;/last_name&gt; &lt;email&gt;john@gmail.com&lt;/email&gt; &lt;age&gt;34&lt;/age&gt; &lt;/book&gt; &lt;book&gt; &lt;book_id&gt;102&lt;/book_id&gt; &lt;book_name&gt;Django&lt;/book_name&gt; &lt;publisher_name&gt;Technical&lt;/publisher_name&gt; &lt;author_id&gt;1003&lt;/author_id&gt; &lt;first_name&gt;Josep&lt;/first_name&gt; &lt;last_name&gt;Raj&lt;/last_name&gt; &lt;email&gt;joseph@gmail.com&lt;/email&gt; &lt;age&gt;29&lt;/age&gt; &lt;/book&gt; </code></pre> <p>What i required is to save the xml data into appropriate fields.From google i learned about paring using single table,here i don't know how to create the object for the "author" table.</p> <p>I tried with the below code </p> <pre><code>for books in xmlDocTree.iter('book'): book_id = books[0].text book_name = books[1].text publisher_name = books[2].text author_id = books[3].text books.first_name = books[0].text books.last_name = books[1].text books.email = books[2].text books.age = books[3].text </code></pre> <p>getting the following traceback</p> <pre><code>AttributeError at /addxml/ first_name Request Method: POST Request URL: http://localhost:8000/addxml/ Django Version: 1.3.7 Exception Type: AttributeError Exception Value: first_name Exception Location: /root/Samples/DemoApp/DemoApp/views.py in addxml, line 106 </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload