- In the terminal,
mkvirtualenv PROJECT_NAME
- In the virtualenv,
pip install django
- In the virtualenv,
pip install psycopg2
- In the virtualenv,
django-admin.py startproject PROJECT_NAME
- If the DB isn't running, in the virtualenv, run
postgres -D /usr/local/var/postgres
- In the virtualenv,
psql postgres
- In postgres, open
create database PROJECT_NAME;
- In PyCharm, create the file
local_settings.py
- In
local_settings.py
paste
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'PROJECT_NAME',
}
}
- In
settings.py
, under theDATABASES
section paster
try:
from local_settings import *
except ImportError:
pass
- In Pycharm, click on PyCharm -> Preferences -> Project Interpreter -> Gear Icon -> Add Local. Go to your home directory -> .virtualenvs -> PROJECT_NAME -> bin ->
python
- In virtualenv,
cd PROJECT_NAME
(same level asmanage.py
- In virtualenv,
python manage.py startapp APP_NAME
- In PyCharm project, open
settings.py
and inINSTALLED_APPS
add'APP_NAME'
- In
models.py
, underfrom django.db import models
paste
class TABLE_NAME(models.Model):
variable1 = models.CharField(max_length=120)
variable2 = models.CharField(max_length=40, null=True)
def __unicode__(self):
return u"{}".format(self.variable1)
- When using the built-in Django admin panel, this step always goes together with creating a data model
- In PyCharm, open
admin.py
and paste
from django.contrib import admin
from your_app.models import TABLE_NAME
class TABLE_NAMEAdmin(admin.ModelAdmin):
fields = ['variable1','variable2']
admin.site.register(TABLE_NAME, TABLE_NAMEAdmin)
- In virtualenv,
python manage.py makemigrations
- In virtualenv,
python manage.py migrate
###Create SuperUser
- In virtualenv,
python manage.py createsuperuser
- In
Username:
, enter an admin_name - In
Email address:
, enter admin_email - In
Password:
, enter a password - In PyCharm, check
settings.py
underINSTALLED_APPS
and make sure you see'django.contrib.admin',