Skip to content

Customizing The Structure

arruda edited this page Nov 21, 2011 · 6 revisions

Customizing the Project Structure

This section will show you how to customize and create your own project structure.

Creating your YAML structure file

The project is created using a Yaml file as base, and you can make your own that covers your needs.

This Yaml file has this structure:

name: $project_name
archives:  
- name: folder1
  archives: []
 
- name: folder2
  archives:
  - name: file.txt
 
- name: $project_name
  archives:  
  - name: __init__.py
 
  - name: manage.py
    snippets: [default.manage.full]
...

And this will make an structure like:

|myProject
|----folder1
|----folder2
     |----file.txt
|----myProject
     |----__init__.py
     |----manage.py
...

Folders

To define a folder just do:

 - name: folder_name
      archives: []

To put files inside a folder just do:

 - name: folder_name
      archives: 
      - name: file_name1
      - name: file_name2

Files

To define a file do it like this:

 - name: file_name

Snippets Inside File

To put a snippet inside a file do this:

 - name: some_file
   snippets: [some.nice.snippet]

To put more then one snippet inside a file:

 - name: some_file
   snippets: [some.nice.snippet,some.other.nice.snippet]

PS: Note that the order that the snippets are declared will be the order that they will appear in the file

Variables For the Structure File

There are some variables that can be used to make things more generic some of them are:

$project_name

Is replaced by the project name when creating a new project.

$app_name

Is replaced by the app name when creating a new app.

$source

This var marks the folder that should contain the source files(the root one, that has the manage.py file)

$app_folder

This var tells Django-Structurer where is the app folder(used to generate your apps)

$create_with_app

Put this var in the folder that should only be created when running the app_starter.py

Using Your Custom Structure

To use the recently created structure file you just do:

djstruct.py proj "project name" /path/to/yaml/file.yaml

Making it Easy

If you want to use different project structures more easily than saying the path to the file, you can use some environment variable to help you out.

See the [Environment Variables](Environment Variables) section to know how.

Creating New Snippets

The snippets that comes with django-structurer is not what you want?

No problem, just create your own: [Creating Custom Snippets](Creating Snippets)