1

I have a few defined apps in my Django project, each with their own sub-directory (created with startapp)

In the views.py of app1 I have an import to a model from app2

from app2.models import MyModel

This worked in Django 1.6.x. In version 1.9 I get:

Could not resolve variable

sometimes on MyModel, sometimes on the filter(..) method, or on both. If I change the import to

from app2.models import * #@UnusedWildImport

then everything works just fine.

Has anything changed in 1.9.x (or before) that requires a different mode of importing models external to the app? I think I can rule our circular import problems as this would have failed in 1.6...

Edit: Based on the comments I started wondering whether this might be a PyDev problem. I tried:

  1. Removing and re-adding Python to PyDev - it did not help

  2. This https://stackoverflow.com/a/8534599/5958359 - removing the myproject/src folder from PYTHONPATH worked ... with a caveat. The error did not appear when I completely removed the import statement, so this is not a good solution

Community
  • 1
  • 1
mibm
  • 1,328
  • 2
  • 13
  • 23
  • I'm using your exact syntax with v1.9.1, and my table imports without error. `from tables.models import Zgtdupe` – Dashdrum Feb 21 '16 at 14:52
  • include your code and the complete traceback -- cut and paste it – joel goldstick Feb 21 '16 at 18:53
  • @joelgoldstick unfortunately the code is too long to include. What I noticed is that the error is **only** in the Eclipse editor ... the code runs just fine ... I noticed this because Eclipse marks errors in a Python file only when the file is open and I had a particular file that was closed ... but its code ran correctly ... when I opened it I got the errors ... so maybe the problem is Eclipse related ... – mibm Feb 22 '16 at 09:29
  • Well, if the code is too long, still copy and paste the complete error message. It will include traceback and line numbers to pinpoint the issue – joel goldstick Feb 22 '16 at 12:09
  • @joelgoldstick the complete error message is "Could not resolve variable" or "Undefined variable from import" depending on whether the error is on the model class or one of the get/filter messages. There is no traceback as the error is compile time in Eclipse. As I mentioned in a previous comment, the code works fine (apparently) when I run it ... I just get an error. – mibm Feb 23 '16 at 08:39

1 Answers1

0

This is a PyDev error.

Searches haven't yielded an adequate solution - most simply explain how to disable the error - so I will not link to any solution here. My workaround, as much as I don't like from xxx import * seems like the best temporary solution.

mibm
  • 1,328
  • 2
  • 13
  • 23