3

I need to create a Django Project with a different files and folder structure. In particular I need to add 2 folders: qqapp and qqproject when creating a new app through the startapp command, each containing some base files.

How can I override the base commands or add a custom one?

My current solution is editing the base commands files (changing dir name for default folders) django/core/management/commands/startapp|project.py, but I think this is bad idea.

Nicolò Gasparini
  • 2,228
  • 2
  • 24
  • 53

2 Answers2

3

Use project templates for this.

django-admin.py startproject --template=/path/to/my_project_template myproject
Bite code
  • 578,959
  • 113
  • 301
  • 329
1

there is a documentation for this: https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

akonsu
  • 28,824
  • 33
  • 119
  • 194
  • i knew about this, but for creation custom commands we need create app and add this into INSTALLED_APPS.. or i'm wrong? – oleg.vodopyan Oct 18 '11 at 08:25
  • btw i want to creat startproject command.. at that moment we didin'y have project, so this not right for me i think – oleg.vodopyan Oct 18 '11 at 08:33
  • I looked at the source: https://code.djangoproject.com/browser/django/trunk/django/core/management/__init__.py#L71 You can install your command in to django.core, in which case you won't need an application. this is still not very clean though. – akonsu Oct 18 '11 at 08:36
  • i use now something like this, it's work, but looking for nice way for this if it possible) – oleg.vodopyan Oct 18 '11 at 11:44
  • do you mean that you want to avoid putting your code in to django/core directory? – akonsu Oct 18 '11 at 12:07
  • I think for that you will have to patch django.core.management module – akonsu Oct 18 '11 at 17:27