#4015
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Fri, 19 Oct 2012 17:40:01 +0000 (13:40 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Fri, 19 Oct 2012 17:40:01 +0000 (13:40 -0400)
src/qbe/django_qbe/utils.py

index 1fbe9da..7830cb0 100644 (file)
@@ -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]