Alexander
Alexander

Reputation: 652

PyDev's inteactive shell with Django problem

I'm going through Django tutorial and using PyDev Eclipse plugin for development.

For interactive testing I use "Interactive shell with Django" which is accessed by Right click on PyDev project -> Django -> Shell with Django environment.

And here is the problem I encountered ("lemonanas" is my project name, "polls" is my app name):

>>from lemonanas.polls.models import Poll, Choice
>>Poll.objects.filter(id=1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "F:\Python27\lib\site-packages\django\db\models\manager.py", line 141, in filter
    return self.get_query_set().filter(*args, **kwargs)
  File "F:\Python27\lib\site-packages\django\db\models\query.py", line 561, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "F:\Python27\lib\site-packages\django\db\models\query.py", line 579, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1170, in add_q
    can_reuse=used_aliases, force_having=force_having)
  File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1058, in add_filter
    negate=negate, process_extras=process_extras)
  File "F:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1225, in setup_joins
    field, model, direct, m2m = opts.get_field_by_name(name)
  File "F:\Python27\lib\site-packages\django\db\models\options.py", line 296, in get_field_by_name
    cache = self.init_name_map()
  File "F:\Python27\lib\site-packages\django\db\models\options.py", line 326, in init_name_map
    for f, model in self.get_all_related_m2m_objects_with_model():
  File "F:\Python27\lib\site-packages\django\db\models\options.py", line 401, in get_all_related_m2m_objects_with_model
    cache = self._fill_related_many_to_many_cache()
  File "F:\Python27\lib\site-packages\django\db\models\options.py", line 415, in _fill_related_many_to_many_cache
    for klass in get_models():
  File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 167, in get_models
    self._populate()
  File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "F:\Python27\lib\site-packages\django\db\models\loading.py", line 76, in load_app
    app_module = import_module(app_name)
  File "F:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named polls

If I use default shell, executing "manage.py shell" - all works fine. But default shell not such comfortable as "Interactive shell with Django".

I noticed that "Interactive shell with Django" does not add my app folder (polls) to python path. And I guess this is the essense of problem. But don't know how to entirely solve all "import/pythonpath/etc." problems with "Interactive shell with Django". Hope you can help me. Thanks.

Upvotes: 0

Views: 1019

Answers (2)

algometrix
algometrix

Reputation: 3992

In Eclipse, right click your project, goto PyDev-> Set as source folder

Upvotes: 0

lprsd
lprsd

Reputation: 87095

Customize the python path, eclipse uses to include the path to the project. (Not each app, just the project folder. - The one that contains settings.py)

Upvotes: 2

Related Questions