This has always bothered me, and I’ve never really come up with my own preferred way of doing this.
When importing something from one of your own applications in a django project, do you import with:
from myproject.mymodule.model import SomeModel
from myproject.anotherone.model import AnotherModel
or, do you do:
from mymodule.model imoprt SomeModel
from anotherone.model import AnotherModel
Of course, either will work as long as you set your PYTHONPATH correctly when deploying. Even a combination of the two within a given project will work.
My issue with the second form is when you have a utils.py or the like sitting in the your project.
# This feels wrong
import utils
But, that could just be me.
Which one is better and why?
I would recommend using the second alternative:
In Django, it’s recommended to write reusable applications, that you may deploy in multiple projects. Specifying the name of the project would hinder this possibility. It would even complicate the case where you simply change the name of the top project folder!
This is the tradition that most django applications use (e.g. pinax, django contrib, etc).
For more details, you should listen to DjangoCon 2008: Reusable Apps.