Fix for cmp items
[auf_rh_dae.git] / src / qbe / django_qbe / utils.py
index 7b6851a..7830cb0 100644 (file)
@@ -56,7 +56,7 @@ def qbe_models(admin_site=None, only_admin_models=False, json=False):
             'name': field.name,
             'type': type(field).__name__,
             'blank': field.blank,
-            'label': u"%s" % field.verbose_name.lower().capitalize(),
+            'label': "%s" % field.verbose_name.lower().capitalize(),
             'primary': field.primary_key,
         }}
 
@@ -88,10 +88,14 @@ def qbe_models(admin_site=None, only_admin_models=False, json=False):
 
     def get_target(field):
         name = field.rel.to.__module__.split(".")[-2].lower().capitalize()
+        try:
+            t_field = field.rel.field_name
+        except:
+            t_field = field.rel.to._meta.pk.name
         target = {
             'name': name,
             'model': field.rel.to.__name__,
-            'field': field.rel.to._meta.pk.name,
+            'field': t_field,
         }
         if hasattr(field.rel, 'through') and field.rel.through is not None:
             name = field.rel.through.__module__.split(".")[-2]
@@ -153,6 +157,8 @@ def qbe_models(admin_site=None, only_admin_models=False, json=False):
                                  # [arrowhead=normal arrowtail=normal]'
                     model = add_relation(model, field, extras=extras)
 
+        model['fields'] = sorted(model['fields'].items())
+
         app_title = app_model._meta.app_label.title().lower().capitalize()
         if app_title not in graphs:
             graphs[app_title] = {}