Skip to content

Instantly share code, notes, and snippets.

from django.contrib import admin
from models import *
admin.site.register(Issue)
from django.db import models
# Create your models here.
ISSUE_TYPE = (
('Broken Streetlight','Broken Streetlight'),
('Pipe Leakage','Pipe Leakage'),
('Pot Hole','Pot Hole'),
('alien infestation','alien infestation'),
('stray dogs','stray dogs'),
('runaway velociraptor','runaways velociraptor')
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'issue'
)
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'citizenwatch.db' # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
<html>
<head>
<title>{% block title %}{% endblock %}</title>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
~
{% extends 'base.html' %}
{% block title %}list issue{% endblock %}
{% block content%}
{% for i in issue %}
<p>
<a href="/issue/view/?id={{i.id}}">{{i.title}}</a> vote:{{i.votes}}
</p>
{% endfor %}
{% endblock %}
from django.conf.urls.defaults import *
from views import *
urlpatterns = patterns('',
(r'add/',add_issue),
(r'view/',view_issue),
(r'list/',list_issue))
from django.shortcuts import render_to_response
from forms import IssueForm
from django.http import HttpResponseRedirect
from models import *
# Create your views here.
def add_issue(request):
if request.method == 'GET':
form = IssueForm()
return render_to_response('issue/add.html',{'form':form})
from django.forms import ModelForm
from models import *
class IssueForm(ModelForm):
class Meta:
model = Issue
exclude = ('closed','votes')
~
{% extends 'base.html' %}
{% block title %}Add Issue{% endblock %}
{% block content %}
<form method="POST" action="/issue/add/">
{{form.as_p}}
<input type="submit" value="report"/>
</form>
{% endblock %}