xxx
[auf_rh_dae.git] / project / dae / management / commands / dae.py
index a688b64..9b83fbd 100644 (file)
@@ -31,7 +31,8 @@ class Command(BaseCommand):
 
         classname = args[0]
         klass = getattr(dae, classname, None)
-        self.stdout.write("Le modèle %s n'existe pas dans DAE.\n" % classname)
+        if klass is None:
+            self.stdout.write("Le modèle %s n'existe pas dans DAE.\n" % classname)
 
         id = int(args[1])
         try:
@@ -50,19 +51,24 @@ class Command(BaseCommand):
         print obj
 
         def duplicate(obj, level=0):
-            print "%s%s" % ("|"*level, type(obj))
-            print "%s%s" % ("|"*level, obj)
+            print "%s [%s] %s" % ("|"*level*4, type(obj), obj)
             for obj_composition in obj._meta._related_objects_cache:
-                app_label, field_name = obj_composition.name.split(':')
+                app_label, dummy = obj_composition.name.split(':')
+                field_name = obj_composition.field.rel.related_name
                 if app_label == obj._meta.app_label:
-                    import pdb; pdb.set_trace()
-                    
-                    sub_obj = getattr(obj, field_name)
-                    duplicate(sub_obj, level+1)
+                    try:
+                        children = getattr(obj, field_name)
+                    except:
+                        print obj_composition
+                        print field_name
+                        continue
+                    for child in children.all():
+                        duplicate(child, level+1)
                 
 
         duplicate(obj)
-
+        import pdb; pdb.set_trace()
+