Skip to content

Commit

Permalink
mongo get_or_create doesn't like lists in queries. Workaround.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Turner committed Nov 3, 2010
1 parent bf63cd5 commit 8e79e35
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions xmltools/lib/xml2dict.py
Expand Up @@ -4,10 +4,10 @@ def xml2dict(tag):
r = {}

#value
# tag.text is None, for empty tags.
if tag.text is not None:
v = tag.text.strip()
if v:
r['_value'] = v
r['_value'] = v

#attributes
if tag.keys():
Expand Down
10 changes: 9 additions & 1 deletion xmltools/processors/mongo.py
Expand Up @@ -30,4 +30,12 @@ def __call__(self, tag):
d = xml2dict(tag)
d = self.clean(d)

m, created = self.model.objects.get_or_create(**d)
if d is not None:
try:
m = self.model.objects.get(id=d['id'])
for k, v in d.iteritems():
setattr(m, k, v)
m.save()
except self.model.DoesNotExist:
m = self.model.objects.create(**d)
m.save()

0 comments on commit 8e79e35

Please sign in to comment.