Autocompletion in Django + pydev
I am trying to make pydev autocomplete my variables from model data, but for now I have been unable to do it.
I have configured the PYTHONPATH in
Window->Preferences->PyDev->Interpreter - Python
to include both the django folder and my project folder.
Then if I have a model like this:
class Team(models.Model):
name = models.CharField(max_length=开发者_JS百科50)
id = models.IntegerField()
and from another file of the same django project I import this file
from MyProject.MyApp.models import Team
Code completion works if I do for instance (I use CTRL+SPACE to show me the autocompletion optiosn)
team = Team.objects.[CTRL+SPACE]
But then it does not work if I want to 'autocomplete' the variables of t. For instance
team.[CTRL+SPACE]
does not give me any options. Any idea on how to solve the problem? Thanks
UPDATE: I have been digging more about the origin of the problem and it is not related with the path configuration or the autocompletion configurations, seems that it has to do with detecting the type of an object (the system is not capable of detecting that team is a Team object, and therefore it does not show the object properties).
Have you added your site packages and your project folder to the PyDev Pythonpath?
Right click on your project folder and...
PyDev > Set as PyDev project
Right click again and...
Properties > PyDev - PYTHONPATH
Click on External Libraries. Click on Add source folder. Choose your project folder and also your site-packages folder. If you're using virtualenv, and of course, why wouldn't you be ;) you'll want to choose the appropriate virtualenv's site-packages. You do not have to choose the system site-packages folder.
Now let's check the autocomplete settings... Window > Preferences > PyDev > Editor > Code Completion
I have autocompletion set on all but the closing parenthesis, with an autocompletion delay of 0. I would also not recommend turning on auto imports.
Hope that gets you going!
Model.object autocompletion is broken, or at least it was in 2008:
http://www.mail-archive.com/django-users@googlegroups.com/msg52874.html
Are you using the last version?
精彩评论