Skip to content

Commit

Permalink
deal with OneToOneField
Browse files Browse the repository at this point in the history
  • Loading branch information
yifanzhang committed Mar 12, 2012
1 parent 7d87faf commit 4bb06cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fixture_magic/management/commands/dump_object.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from optparse import make_option

from django.core.exceptions import FieldError, ObjectDoesNotExist
Expand Down Expand Up @@ -59,6 +60,8 @@ def handle(self, *args, **options):
for rel in related_fields:
try:
add_to_serialize_list(obj.__getattribute__(rel).all())
except AttributeError:
add_to_serialize_list(obj.__getattribute__(rel))
except FieldError:
pass
except ObjectDoesNotExist:
Expand Down
4 changes: 4 additions & 0 deletions fixture_magic/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
import collections

serialize_me = []
seen = {}
Expand Down Expand Up @@ -47,6 +48,9 @@ def serialize_fully():


def add_to_serialize_list(objs):
if not isinstance(objs, collections.Iterable):
objs = [ objs ]

for obj in objs:
if obj is None:
continue
Expand Down

0 comments on commit 4bb06cd

Please sign in to comment.