tags:

views:

58

answers:

1

Hi, everyone I'm just starting with django. It is not quite clear to me, how should I write an app I could reuse later. In every tutorial I read I see the same piece of code:

view.py
from project.app.models import MyModel

So, if I move my apps to another project, I'll have to modify the "project.app.models" so that it looks like "project2.app.models" for every app I move. Is there a way to avoid that?

Thanks in advance.

+3  A: 

You should update your Python path with the directory containing your apps.

This way you just have to :

from app.models import MyModel
Pierre-Jean Coudert
This is the best way to handle imports, but a word of caution: don't mix both styles. If you mix the two styles there will be multiple signals dispatched for the model (in other words when you save a model there will be two pre-save signals sent, two post-save, etc.)
Van Gale
If I remember correctly the problem Van's talking about was going to be fixed in 1.2, which is coming out any day now.
Ludwik Trammer