Question

PyCharm allows you to auto-import a class that is not found... So for instance if I typed a method name or class name, that is not found in the current file, PyCharm can automatically add an import statement for it. However, the problem is that the auto-import misses the current Django projects name...

So for example:

Your Django project is called myproject, and the current application is myapp. You have a class in your models.py called MyModel.

If you type in "MyModel" somewhere, the automatically generated import statement will be:

from myapp.models import MyModel

I however want it to be:

from myproject.myapp.models import MyModel

Does anyone have any idea how this can be fixed?

Was it helpful?

Solution

It`s a bad practice to include project name into imports. It makes harder to reuse your app. And you cannot easily change project name if you want to. Some hostings like ep.io even requires to not use a project name in imports. And afaik you cannot change such import behavoiur in PyCharm. You can try to fill a request at their bugtracker, but i doudt that it will be implemented.

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