Skip to content

ochomoswill/ajira

Repository files navigation

Django Install

Set up a development structure:

$ mkdir uonProject
$ cd uonProject
$ virtualenv -p /usr/bin/python3.5 envProject
$ source envProject/bin/activate

You should see sh (envProject) before your prompt, sh (envProject)$ , indicating that your virtualenv is activated.

To deactivate the virtualenv:

$ deactivate

Then reactivate once you’re ready to start developing again.

With your virtualenv activated, install Django with Pip:

$ pip install django==1.8.1

You can check the version by running the following commands:

$ python
>>> import django
>>> django.get_version()
'1.8.1'
>>>

Project setup

Setup Django project

$ django-admin.py startproject ajira

Creating App

$ python manage.py startapp ajiriwa
$ python manage.py startapp mwajiri

Connecting to MySQL_Db

$ pip install wheel
$ pip install pymysql

In settings.py

import pymysql
pymysql.install_as_MySQLdb()


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'cms',
        'HOST': 'localhost',
        'PORT': '3306',
        'USER': 'root',
        'PASSWORD': '',
    }
}

accessing db terminal:

$ mysql -u root -p test_db

http://g2pc1.bu.edu/~qzpeng/manual/MySQL%20Commands.htm

Creating Models

Change your models (in models.py).

Include App('ajiriwa' and 'mwajiri') in the settings.py

Run sh $ python manage.py makemigrations blog- to create migrations for those changes Run sh $ python manage.py migrate - to apply those changes to the database.

Runserver

$ python manage.py runserver

Creating an Admin User

$ python manage.py createsuperuser

python from .models import Post - add on admin.py