On Sun, 2007-10-21 at 00:18 +0000, james_027 wrote:
> hi,
> 
> i have made myself a module name utilities.py and shortcuts.py and
> place them in the root folder of my django app.
> 
> When I use them in views.py or forms.py I just put a
> 
> from app_name.shortcut import *
> from app_name.utilities import *
> 
> but when I try to use it on my models.py in my forms.py it seems that
> the from app_name.XXX.models import * doesn't work anymore.

"Doesn't work" is not very informative. Does it raise an error? Do
nothing? What is the difference between "works" and "doesn't work" in
this case.

By the way, if it is a circular import issue, as Marty surmises, one
solution is to not "import *". Just do

        from app_name import shortcut, utilities
        
That avoids almost all circular import issues, since it loads the
modules' names into sys.modules, but doesn't try to do any name
resolution inside them. Only when you actually *use* the functions
inside them (which is hopefully inside your own functions in models.py
and not at the top-level of that module) will Python need to do name
resolution and by that stage all the importing will have finished. There
are ways to trip up even this process, but that's usually a sign of
unfortunate design and it would be time to factor out the common pieces.

Regards,
Malcolm

-- 
What if there were no hypothetical questions? 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to