Having a xml field in your postgres database table, you may want to match something with xpath.
Unfortunately the result of the match is an ARRAY, and the django.db.backends.postgresql_psycopg2 engine does not convert it properly to a list of ElementTree's.
But, this can be changed:
import xml.etree.ElementTree as ET
from psycopg2.extensions import new_type, register_type
from psycopg2.extensions import STRINGARRAY
def cast_xml_array(value, cur):
if value is None:
elements = STRINGARRAY(value,cur)
return [ET.fromstring(i) for i in elements]
XML = new_type((143,), "XML", cast_xml_array)
This snippet registers a new type for the OID 143, which is xml for me.
The result is converted to a list of strings using psycopg2's internal STRINGARRAY type, and this list of strings is converted to a list of ElementTrees.
<jcanto> workmate: 'Django is like a cheap whore: takes some time to understand her, but then it makes lots of stuff for a little spending
As the Berlusconi in me was convinced rather instantly, I decided to give django a shot.
Current projectname is carniwwwhore, and as I know I suck in this webdev, I'm looking for people who want to participate, so this flower survives the cold season.
I basically just tested how to get things done with django, and from what I can say, jcanto's workmate is correct.
Due to my lack of love towards html and css, it looks ugly, but given the MVC and use of templates, making it look pretty should be easy for somebody who wants a pretty presentation.
Given my obvious anticipation towards html, I spent most of the time on the filters …
Printing the connections recursively was a pita, but it works …