Question

I'm attempting to use sphinx to document the django app I'm writing. So far I have my code.rst setup to look at models.py, and when I run make html I get the automatic documentation, however I get a warning:

WARNING: autodoc can't import/find attribute 'myapp.models.MyModel.image', it reported error: "image", please check your spelling and sys.path

The entire tracelog is:

Traceback (most recent call last):
  File "C:\blah\lib\site-packages\sphinx\ext\autodoc.py", line 326, in import_object
    obj = self.get_attr(obj, part)
  File "C:\blah\lib\site-packages\sphinx\ext\autodoc.py", line 232, in get_attr
    return safe_getattr(obj, name, *defargs)
  File "C:\blah\lib\site-packages\sphinx\util\inspect.py", line 70, in safe_getattr
    raise AttributeError(name)
AttributeError: image

MyModel.image is an image field, simply on the model defined as:

#: image file location for ``MyModel``
image = models.ImageField(upload_to="images/")

If I change image to models.Charfield for example it runs fine. Is there any reason why an ImageField would cause sphinx issues?

my code.rst:

.. automodule:: dynamicbanners.models
   :members:
Was it helpful?

Solution

So after reading the comments it seems this is a quirk of Django that messes with sphinx.ext.autodoc. Hopefully a fix will be dropped into Django 1.6 soon, or failing that I think the upcoming 1.2 version of Sphinx might provide a way around it, but for now I'll need to find some sort of workaround.

OTHER TIPS

Looks like this was fixed in Django 1.8 - https://code.djangoproject.com/ticket/12568

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top