On Tue, May 13, 2014 at 8:40 PM, Sayth Renshaw <flebber.c...@gmail.com> wrote:
> Can I ask for some assistance please.
>
> For my project I will need to upate the database from an external xml file
> consistently. The xml is like this one
> http://old.racingnsw.com.au/Site/_content/racebooks/20140515GOSF0.xml
> If i have create my model objects, most of which will have a direct
> correlation to the xml file, but there will be extra model objects and
> fields relating to user input. How can I do updates to my database via xml.
>
> There are 2 docs I have been reviewing
> https://docs.djangoproject.com/en/1.6/howto/initial-data/#providing-initial-data-with-fixtures
> and https://docs.djangoproject.com/en/1.6/topics/serialization/.
>
> The guides talk about creating a fixture but I am not sure it is appropriate
> exactly and I am unsure from the guide how I would setup a mapping so that
> the xml data went to the correct model object.
> How do I do this?
>

I don't think you want fixtures, even though there are XML fixtures.
This is basically a data feed which periodically you wish to import in
to your own database. Fixtures are normally exports of your own
database. I think it would be very difficult to ensure that your
database always matches the contents of an XML file produced by a 3rd
party.

You could use xslt to transform the 3rd party xml in to the right
format for an xml serialisation, but that would involve using xslt.

What I would do is write a management command that parses the XML (I
like lxml), and then iterates through it, using xpath to pull out
relevant parts of the doc, and then use standard django models to
create this data in the database, taking care not to insert duplicate
data when it exists in both DB and XML.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KCPYxxL%3Duj2CQkX1EiC5Y%3D-DsBSfOqm5YykbxXWT%2B_dA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to