The library uses a Google spreadsheet to generates django applications.
- The Google spreadsheet works as a functional and technical analysis document that can be presented to the database stakeholders. By using the spreadsheet document to generate code the developer makes sure that his code is according to what was agreed with the stakeholders.
- One other advantage is that the Google spreadsheet document can be edited in colaboration with several users at the same time. Also all the changes are tracked in the document history log.
- Create a django project and configure the django-suit application.
- Download and install the library googlespreadsheet2django using the command: python setup.py install
- Make a copy of this Google spreadsheet document and edit the tables and fields of your database.
- Configure the document to be shared with everyone with the link (this is necessary for the code generator script to download the file).
- Open the terminal and go to the created django project directory.
- Use the command: gsheet2django "<id of the Google spreasheet document>" to generate the code of your django applications.
- Add the new applications to the settings.py file.
For the Google spreadsheet template, the gsheet2django will generate the next files:
├── details
│ ├── abstractmodels
│ │ ├── Country.py
│ │ ├── __init__.py
│ │ └── Person.py
│ ├── admins
│ │ ├── CountryAdmin.py
│ │ ├── __init__.py
│ │ └── PersonAdmin.py
│ ├── __init__.py
│ ├── models.py
│ └── admin.py
└── static
└── js
└── models
├── country.js
└── person.js
- The abstractmodels and admins folders describes the Models, and their visualisation in the admin interface. The files on these folders should not be touched, never!! because they will be replaced everytime you generate a the code.
- In the files models.py and admin.py you will see comments like these ones:
##### auto:start:Person #####
... some code ...
##### auto:end:Person #####
These comments indicate which parts of the code would be replaced when ever you generate a new code based on the spreadsheet. All the code outside these comments will be kept, which means that you can use these files to add extra rules or fields to your application.
- The static -> js files implement the hide and show rules of the fields.
In the "Applications" tab we will see a column the title "Applications" as in the image below. Here we should add in each row the django applications which we would like to generate.
To add a new table we should select the option "Database application -> Add new table" in the Google spreadsheet main menu, as in the image bellow.
After we select the option a popup window will ask you for the name of the new table.
After the OK, a new tab will be generated with the format "Table_<name you gave for the table>".
On the top of the tab spreadsheet we will configure which application the table bellongs to in the field <Select an application>.
If we click on this field, a dropdown box will be shown with the applications configured in the tab "Applications".
The fields <Table singular label> and <Table plural label> are the names of the table that will be used in the django admin interface.
The field <Data access> allow us to configure which type of access we would like to have on this table. Check the available options in the image bellow.
By default the table is added with a primary key set.
To add new fields you should use the option "Database application -> Add new field" in the Google spreadsheet main menu, as in the image bellow.
A new row will appear in the spreadsheet, where you should configure your fields properties.
The details of fields configurations columns are explained in the table below.
The choices tab is used to configure the values of the Dropdown lists and Radio buttons lists fields.
The value in the "Answer identifier" column should be unique to each set of values, and should respect a python variable format.