Repository: django-extensions/django-extensions

Issue:
The `graph_models` command does not work with `settings.AUTH_USER_MODEL`.
I installed the extensions in a project that is is also a Django plugin so it must support any user objects that may be created by a user of my plugin. The command below broke even though the value in `settings.AUTH_USER_MODEL` (`auth.User`) is considered to be explicit. The command is:

```
./manage.py graph_models -a -o dcolumn_models.png
```

and I got the error:

```
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django_extensions/management/utils.py", line 57, in inner
    ret = func(self, *args, **kwargs)
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django_extensions/management/commands/graph_models.py", line 77, in handle
    dotdata = generate_dot(args, cli_options=cli_options, **options)
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django_extensions/management/modelviz.py", line 243, in generate_dot
    add_relation(field, '[arrowhead=none, arrowtail=dot, dir=both]')
  File "/home/cnobile/.virtualenvs/dcolumn/local/lib/python2.7/site-packages/django_extensions/management/modelviz.py", line 217, in add_relation
    raise Exception("Lazy relationship for model (%s) must be explicit for field (%s)" % (field.model.__name__, field.name))
Exception: Lazy relationship for model (UserModelMixin) must be explicit for field (updater)
```

The `UserModelMixin` is using `settings.AUTH_USER_MODEL`.



Discussion:
+1 on this one.

@trbs - I created an issue on the google group [here](https://groups.google.com/forum/#!topic/django-extensions/FRkZOdI4pAE), which upon reading this issue, is actually the same thing. The error message seems to have come from #463 

EDIT: I forgot to mention in my group post that I am also using a `settings.AUTH_USER_MODEL`


Resolving patch:
diff --git a/django_extensions/management/modelviz.py b/django_extensions/management/modelviz.py
--- a/django_extensions/management/modelviz.py
+++ b/django_extensions/management/modelviz.py
@@ -13,6 +13,7 @@
 
 import six
 import django
+from django.apps import apps
 from django.db.models.fields.related import (
     ForeignKey, ManyToManyField, OneToOneField, RelatedField,
 )
@@ -46,7 +47,8 @@
     "Alexander Houben <alexander@houben.ch>",
     "Joern Hees <gitdev@joernhees.de>",
     "Kevin Cherepski <cherepski@gmail.com>",
-    "Jose Tomas Tocino <theom3ga@gmail.com>"
+    "Jose Tomas Tocino <theom3ga@gmail.com>",
+    "Adam Dobrawy <naczelnik@jawnosc.tk>"
 ]
 
 
@@ -216,7 +218,7 @@ def add_relation(field, extras=""):
                     if field.rel.to == 'self':
                         target_model = field.model
                     else:
-                        raise Exception("Lazy relationship for model (%s) must be explicit for field (%s)" % (field.model.__name__, field.name))
+                        target_model = apps.get_model(*field.rel.to.split('.'))
                 else:
                     target_model = field.rel.to
 


Test patch: