djangodjango-modelsdjango-commands

django directory structure of module for commands


in django 1.6, I have a commands for make analysis over the database, with a set of functions.

├── management
│   ├── __init__.py
│   └── commands
│       ├── __init__.py
│       ├── analysis.py

I like break the analysis.py in a set of files (maybe a module ...). what is the correct directory structure for a module use for a django command ?

maybe like this ... ?

├── management
│   ├── __init__.py
│   ├── analysis_module
│   └── commands
│       ├── __init__.py
│       ├── analysis.py

and the test for the analysis_module, what is the correct ubication for the test of analysis_module ?


Solution

  • a option, put the code modude out of django project

    ├── analysis_module
    ├── test
    ├── django_project
    │   ├── app
    │   │   ├── __init__.py
    │   │   ├── admin.py
    │   │   ├── management
    │   │   │   ├── __init__.py
    │   │   │   └── commands
    │   │   │       ├── __init__.py
    │   │   │       └── analysis.py
    │   │   ├── models.py
    │   │   ├── tests.py
    │   │   ├── urls.pyc
    │   │   └── views.py
    │   └── django_proyect
    │       ├── __init__.py
    │       ├── settings.py
    │       ├── urls.py
    │       └── wsgi.py
    

    but for this, I need add the module to path to the sys.path maybe in manage.py

    # manage.py
    sys.path.append(os.path.abspath(__file__ + '/../../'))
    

    and import from the analysis command

    # analysis.py
    import analysis_module
    

    with this I can put the test for analysis_module separately.