Recommended OS:
Ubuntu 12.04 LTS
Required softwares:
- Python2.7 (Recommended) - Provided default on Ubuntu 12.04 LTS
- pip Python Package - run these commands on terminal 'wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py' 'python get-pip.py'
- virtualenv and virtualenvwrapper 'pip install virtualenv' 'pip install virtualenvwrapper'
Virtual Environment Setup:
- After installing virtualenv and virtualenvwrapper, edit ~/.bashrc by adding these lines at the bottom:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Development
source /usr/local/bin/virtualenvwrapper.sh
-
Exit and open a new terminal.
-
Run this command: 'mkvirtualenv 1northsoft-examples'
-
Make sure that whenever we need to run the server we need to be in the virtualenv. The same when we want to install new python packages.
-
More about virtualenv: 'http://www.silverwareconsulting.com/index.cfm/2012/7/24/Getting-Started-with-virtualenv-and-virtualenvwrapper-in-Python'
Installing required packages used in project
-
Find 'requirements.txt' in the project folder.
-
Run 'workon 1northsoft-examples' and make sure the terminal is under 1northsoft-examples environment.
-
Run 'pip install -r requirements.txt' -- installs all required packages for this project.
Storing Entities
-
Django uses MVC Framework and entities are stored into the database according to the attributes of the entity / model.
-
When a project is created the project structure is as follows:
MyProject (created using 'django.admin.py startproject MyProject')
|-- manage.py
|-- MyProject (Contains all settings regarding the project)
|-- __init__.py |-- settings.py # Project settings |-- urls.py # Url specification and settings |-- wsgi.py # For use with Apache|-- NewApplication (created using 'python manage.py startapp
NewApplication'
|-- __init__.py
|-- admin.py # Admin page configuration
|-- models.py # Add models / entities to be stored in database here
|-- tests.py # Unit Tests codes.
|-- views.py # View function to handle requests.
-
How to add models: 'https://docs.djangoproject.com/en/1.6/topics /db/models/'
-
Model field types: 'https://docs.djangoproject.com/en/1.6/ref/models/fields /#model-field-types'
-
After added the models, to create the database tables, run: "python manage.py syncdb"
-
Check the database tables and they are created.
Setting up Django with databases other than sqlite3:
-
Default django database used is sqlite3, a file-based database system, under the extension '.db'
-
Settings of other databases: https://docs.djangoproject.com/en/dev/ref/databases/#connecting-to-the-database