Hi there,

Well, it is quite simple but let's break it down:

> to me the command "from myproject.myapp.models import Author" should
> be
> either
> 
>    from myapp.models import Author
> or
>    from models import Author # in the same folder as myapp.models.


1) If you use "from myapp.models import Author" then "myapp" is supposed to be 
pluggable app. If so, it should not be located within "myproject" as it is kind 
of library for django projects. On the other hand, as you write your apps you 
are not always sure if this should be pluggable or not, especially at the early 
stage. Most of the time it probably should but if you know about PYTHONPATH 
(and virtualenv maybe) you can figure it out on your own how to split your 
project/apps. Tutorial at Django website is aimed for people with little python 
knowledge, really. Just use "from someapp.package..." statements for external 
(from the point of view of your project) apps and "from 
myproject.projectapp..." statements for internal (not pluggable) apps.

2) Definitely "from models" is not a good idea - there should be clear 
statement about where are classes imported from. Adding "app_name" into import 
statement makes it very clear.

You may also read http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango - 
it has some references to import statements in django projects.


On Jan 10, 2010, at 3:04 PM, ruckus tak wrote:

> Hi,
> 
> +------------------------------------------------------------------------------------------------------------
> +
>  Does anyone know why the project-name included in the import
> statement?
> +------------------------------------------------------------------------------------------------------------
> +
> 
> One thing I cannot understand in Django is the <project name> included
> in the import statement.
> For example from djangoproject admin document:
> 
>    from django.contrib import admin
>    from myproject.myapp.models import Author
> 
>    class AuthorAdmin(admin.ModelAdmin):
>        pass
>    admin.site.register(Author, AuthorAdmin)
> 
> to me the command "from myproject.myapp.models import Author" should
> be
> either
> 
>    from myapp.models import Author
> or
>    from models import Author # in the same folder as myapp.models.
> 
> My view is project-name is a container, applications inside the
> container deal with other applications in the container or defined in
> the PYTHONPATH.
> 2nd if you would like to share the application with other project;
> then definitely the application should not refer to any project name
> -- an application can refer to other applications, but it should not
> refer to an application of other project which i might not have the
> right to access to it, but only the application.
> 
> Does anyone know why the project-name included in the import
> statement?
> 
> Thanks in advance.
> tak
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

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


Reply via email to