wheelersalmon
New Member
I written a function to save the data in xml file to database.I am using two models ,see the below.models.py \[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\]my .xml file is\[code\] <book> <book_id>101</book_id> <book_name>Python</book_name> <publisher_name>Maxwell</publisher_name> <author_id>1002</author_id> <first_name>John</first_name> <last_name>Dezosa</last_name> <email>[email protected]</email> <age>34</age> </book> <book> <book_id>102</book_id> <book_name>Django</book_name> <publisher_name>Technical</publisher_name> <author_id>1003</author_id> <first_name>Josep</first_name> <last_name>Raj</last_name> <email>[email protected]</email> <age>29</age> </book> \[/code\]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.I tried with the below code \[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\]getting the following traceback\[code\]AttributeError at /addxml/first_nameRequest Method: POSTRequest URL: http://localhost:8000/addxml/Django Version: 1.3.7Exception Type: AttributeErrorException Value: first_nameException Location: /root/Samples/DemoApp/DemoApp/views.py in addxml, line 106\[/code\]Thanks