Skip to content

Commit 0eaf706

Browse files
committed
django note app
0 parents  commit 0eaf706

16 files changed

+272
-0
lines changed

.gitignore

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Windows image file caches
2+
Thumbs.db
3+
ehthumbs.db
4+
5+
# Folder config file
6+
Desktop.ini
7+
8+
# Recycle Bin used on file shares
9+
$RECYCLE.BIN/
10+
11+
# Windows Installer files
12+
*.cab
13+
*.msi
14+
*.msm
15+
*.msp
16+
17+
# Windows shortcuts
18+
*.lnk
19+
20+
# =========================
21+
# Operating System Files
22+
# =========================
23+
24+
# OSX
25+
# =========================
26+
27+
.DS_Store
28+
.AppleDouble
29+
.LSOverride
30+
31+
# Thumbnails
32+
._*
33+
34+
# Files that might appear on external disk
35+
.Spotlight-V100
36+
.Trashes
37+
38+
# Directories potentially created on remote AFP share
39+
.AppleDB
40+
.AppleDesktop
41+
Network Trash Folder
42+
Temporary Items
43+
.apdisk
44+
45+
46+
#python compiled files
47+
*.pyc
48+
#and cache
49+
mytweets/__pycache__
50+
.idea
51+
.gitignore

db.sqlite3

37 KB
Binary file not shown.

manage.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "note_app.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

note_app/__init__.py

Whitespace-only changes.

note_app/settings.py

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""
2+
Django settings for note_app project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.7/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.7/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14+
15+
16+
# Quick-start development settings - unsuitable for production
17+
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
18+
19+
# SECURITY WARNING: keep the secret key used in production secret!
20+
SECRET_KEY = 'jk2j%o(&zjh38&6mo&fo*8lz%ad0*mxdsfi($jmn*1694@8zk9'
21+
22+
# SECURITY WARNING: don't run with debug turned on in production!
23+
DEBUG = True
24+
25+
TEMPLATE_DEBUG = True
26+
27+
ALLOWED_HOSTS = []
28+
29+
30+
# Application definition
31+
32+
INSTALLED_APPS = (
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
'notes',
40+
)
41+
42+
MIDDLEWARE_CLASSES = (
43+
'django.contrib.sessions.middleware.SessionMiddleware',
44+
'django.middleware.common.CommonMiddleware',
45+
'django.middleware.csrf.CsrfViewMiddleware',
46+
'django.contrib.auth.middleware.AuthenticationMiddleware',
47+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
48+
'django.contrib.messages.middleware.MessageMiddleware',
49+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
50+
)
51+
52+
ROOT_URLCONF = 'note_app.urls'
53+
54+
WSGI_APPLICATION = 'note_app.wsgi.application'
55+
56+
57+
# Database
58+
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
59+
60+
DATABASES = {
61+
'default': {
62+
'ENGINE': 'django.db.backends.sqlite3',
63+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
64+
}
65+
}
66+
67+
# Internationalization
68+
# https://docs.djangoproject.com/en/1.7/topics/i18n/
69+
70+
LANGUAGE_CODE = 'en-us'
71+
72+
TIME_ZONE = 'UTC'
73+
74+
USE_I18N = True
75+
76+
USE_L10N = True
77+
78+
USE_TZ = True
79+
80+
81+
# Static files (CSS, JavaScript, Images)
82+
# https://docs.djangoproject.com/en/1.7/howto/static-files/
83+
84+
STATIC_URL = '/static/'
85+
86+
TEMPLATE_DIRS = (os.path.join(os.path.dirname(BASE_DIR), 'note_app', 'static', 'templates'),)
87+

note_app/urls.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.conf.urls import patterns, include, url
2+
from django.contrib import admin
3+
4+
urlpatterns = patterns('',
5+
# Examples:
6+
# url(r'^$', 'note_app.views.home', name='home'),
7+
# url(r'^blog/', include('blog.urls')),
8+
9+
url(r'^admin/', include(admin.site.urls)),
10+
url(r'^$', 'notes.views.home', name='home'),
11+
)

note_app/wsgi.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
WSGI config for note_app project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "note_app.settings")
12+
13+
from django.core.wsgi import get_wsgi_application
14+
application = get_wsgi_application()

notes/__init__.py

Whitespace-only changes.

notes/admin.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
4+
5+
from .models import Note
6+
7+
8+
class NoteAdmin(admin.ModelAdmin):
9+
class Meta:
10+
model = Note
11+
12+
13+
admin.site.register(Note, NoteAdmin)

notes/forms.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django import forms
2+
from .models import Note
3+
4+
class NoteForm(forms.ModelForm):
5+
class Meta:
6+
model = Note

notes/migrations/0001_initial.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
]
11+
12+
operations = [
13+
migrations.CreateModel(
14+
name='Note',
15+
fields=[
16+
('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)),
17+
('text', models.CharField(max_length=120)),
18+
('created', models.DateTimeField(auto_now_add=True)),
19+
],
20+
options={
21+
},
22+
bases=(models.Model,),
23+
),
24+
]

notes/migrations/__init__.py

Whitespace-only changes.

notes/models.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.db import models
2+
3+
4+
# Create your models here.
5+
6+
class Note(models.Model):
7+
text = models.CharField(max_length=120)
8+
created = models.DateTimeField(auto_now_add=True)

notes/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

notes/views.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.shortcuts import render,render_to_response, RequestContext
2+
from django.template import RequestContext, loader
3+
from django.http import HttpResponse
4+
from .models import Note
5+
from .forms import NoteForm
6+
7+
8+
# Create your views here.
9+
10+
11+
def home(request):
12+
notes = Note.objects
13+
template = loader.get_template('note.html')
14+
form = NoteForm(request.POST or None)
15+
if form.is_valid():
16+
save_it = form.save(commit=False)
17+
save_it.save()
18+
19+
context = {'notes': notes, 'form': form}
20+
return render(request, 'note.html', context)
21+
#return render_to_response('note.html', notes)

static/templates/note.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<link href="http://codepen.io/edbond88/pen/CcgvA.css" media="screen" rel="stylesheet" type="text/css" />\
5+
<style>
6+
body{
7+
background: rgba(222,222,222,1);
8+
margin: 20px;
9+
}
10+
</style>
11+
</head>
12+
<body>
13+
<h2>Django Notes App</h2>
14+
{% for note in notes.all %}
15+
<aside class="note-wrap note-white">
16+
{{ note.text }}
17+
</aside>
18+
{% endfor %}
19+
<form method='POST' action=''>{% csrf_token %}
20+
{{ form.as_p }}
21+
<input type="submit" value="Add note">
22+
</form>
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)