How to create a sub-app directly

886 views
Skip to first unread message

Jim

unread,
Aug 21, 2011, 11:22:13 AM8/21/11
to django...@googlegroups.com
Hello folks,

Here is the story. I created a site, mysite, with this command django-admin startproject mysite. Then, under the directory mysite/, I created an app named apps with this command ./manage.py startapp apps. apps is meant to hold all applications for mysite. Now, here comes the question: 
How do I create a sub-app under apps with manage.py directly?

I tried 
../manage.py startapp someapp 
under apps/, but that created the someapp under mysite/ rather than under apps/. 

I also tried 
./manage.py startapp apps/someapp 
and 
./manage.py startapp apps.someapp
under mysite/, but neither worked.

So, my current work-around is to create a sub-app under mysite/ first, then move it into apps/ manually. But that seems dumb, and I suspect there is a simpler way to do this. 

Thanks for reading this. Any help is certainly appreciated.

Jim

Subhranath Chunder

unread,
Aug 21, 2011, 11:27:54 AM8/21/11
to django...@googlegroups.com
Extend the manage.py functionality, by adding your custom command.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/QtvEmvU5QvMJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Thanks,
Subhranath Chunder.

Praveen Krishna R

unread,
Aug 21, 2011, 12:43:18 PM8/21/11
to django...@googlegroups.com
Is there  a concept of sub-apps exist in Django !?
I knew some concepts like independant reusable apps.
You can easily handle the rest with your urls right ?! correct me?
Thanks and Regards,
Praveen Krishna R

Subhranath Chunder

unread,
Aug 21, 2011, 1:04:20 PM8/21/11
to django...@googlegroups.com
From what I understood, by "sub-apps" Jim meant creating the application in a sub-directory, or more specifically maybe inside another python package, using the manage.py command for the sake of convenience and creating using a single command.
Thanks,
Subhranath Chunder.

Mike Dewhirst

unread,
Aug 21, 2011, 10:40:58 PM8/21/11
to django...@googlegroups.com
On 22/08/2011 1:22am, Jim wrote:
> I tried
> ../manage.py startapp someapp
> under apps/, but that created the someapp under mysite/ rather than
> under apps/.
>

That's what is expected.

mysite should contain settings.py and mysite/apps should contain
models.py (among other files). If you want a separate database to
contain data used by all applications there is nothing wrong with
creating a new subdirectory mysite/common (someone here felt that
"global" might be a reserved word) and copying the contents of
mysite/apps into mysite/common. Then in settings.py put mysite.apps and
mysite.common into INSTALLED_APPS.

I would adjust the name "apps" to something more specific for a single
app. You can have a dozen app directories under mysite if you like. In
fact that is good. Segregate your project into as many stand-alone apps
as you feel comfortable doing - but they should all be at the same level
for keystroke minimisation when importing.

---- mysite (settings.py, urls.py etc)
---- ---- app1 (models.py, urls.py etc)
---- ---- app2 (urls.py)
---- ---- ---- models (whatever.py containing just the whatever model)
---- ---- app3(models.py)
---- ---- ---- urls (this.py containing just the this urls)
---- ---- ---- views (lots of files keeping your views under control)

Because you import the bits and pieces as required it is best to keep
things as flat as dictated by the inherent complexity of your project.
In the diagram above, app1 is fairly simple, app2 has many complex
models so you put them into separate files in a models sub-dir, while
app3 has simple models but lots of complex urls which would be best in a
separate urls directory and likewise for app3's views.

hth

Mike

Jim

unread,
Aug 21, 2011, 10:51:29 PM8/21/11
to django...@googlegroups.com
Thank you, folks. I am new to django. I read  a blog the other day that suggests put all applications under a common directory, such as apps, to make the site directory neat, and I think that seems a good idea. That's why I thought it would be wonderful if manage.py could make an app under a given directory, which is apps/ in my case. 

Anyway, it is always nice to hear other people's ideas. Again, thank you very much.

kenneth gonsalves

unread,
Aug 22, 2011, 3:32:22 AM8/22/11
to django...@googlegroups.com
On Sun, 2011-08-21 at 08:22 -0700, Jim wrote:
>
> Here is the story. I created a site, mysite, with this command
> django-admin startproject mysite. Then, under the directory mysite/, I
> created an app named apps with this command ./manage.py startapp apps.
> apps is meant to hold all applications for mysite. Now, here comes the
> question: How do I create a sub-app under apps with manage.py
> directly?

one way to do this:
cd apps
mkdir subapp
cd subapp
touch models.py
touch views.py
touch tests.py

--
regards
Kenneth Gonsalves

in...@webbricks.co.uk

unread,
Aug 22, 2011, 3:57:29 AM8/22/11
to Django users
which is fine, but you've missed the only step that actually makes the
folder a python module.

do this or it'll never import
touch __init__.py

kenneth gonsalves

unread,
Aug 22, 2011, 4:59:59 AM8/22/11
to django...@googlegroups.com
On Mon, 2011-08-22 at 00:57 -0700, in...@webbricks.co.uk wrote:
> which is fine, but you've missed the only step that actually makes the
> folder a python module.
>
> do this or it'll never import
> touch __init__.py

got distracted and pressed send too soon.
--
regards
Kenneth Gonsalves

Reply all
Reply to author
Forward
0 new messages