FINAL PROJECT LAYOUT
PROJECTNAME/manage.py
PROJECTNAME/PROJECTNAME/settings.py
PROJECTNAME/PROJECTNAME/urls.py
PROJECTNAME/APPNAME/models.py
PROJECTNAME/APPNAME/tests.py
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ENABLE ADMIN by uncommenting "django.contrib.admin" in the INSTALLED_APPS setting.
nano PROJECTNAME/APPNAME/settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'polls',
'posts',
)
./manage.py syncdb
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nano blog/blog/urls.py
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'blog.views.home', name='home'),
# url(r'^blog/', include('blog.blog.urls')),
# url(r'^blog/', include('blog.polls.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nano PROJECTNAME/models.py
from django.db import models
class Post(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
created = models.DateTimeField(auto_now_add=True)
slug = models.SlugField(
unique_for_date='pub_date',
help_text='Automatically built from the title.'
)
def __unicode__(self):
return self.title
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nano blog/posts/admin.py # must be created
from django.contrib import admin
from posts.models import Post
admin.site.register(Post)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
./manage.py validate # ensures indentation too
./manage.py syncdb
./manage.py sql posts
./manage.py sql polls
./manage.py syncdb
./manage.py runserver