TODOバージョン1
・項目名、・完了フラグ のみで、
リストは、未完表示、全件表示のものを作る。
新規タスクの追加まで
未完表示を、QuerySetで、Filterかけようとしてるけどうまくいかず(苦戦中)
後は、newforms使ってみよう
成果物:
models.py
from django.db import models # Create your models here. class Task(models.Model): task_id = models.AutoField(primary_key=True) contents = models.TextField(_('Contents')) status = models.BooleanField(_('Status')) class Admin: list_display = ('contents')
urls.py
from django.conf.urls.defaults import * from todo.task.models import * urlpatterns = patterns('', # Example: (r'^$','django.views.generic.list_detail.object_list',{'queryset': Task.objects.all(),'allow_empty': True}), # (r'^noend/$','django.views.generic.list_detail.object_list',{'queryset': Task.objects.all(),'allow_empty': True}), (r'^add/$','django.views.generic.create_update.create_object',{'model': Task, 'post_save_redirect': '/'}), #(r'^task/add/$', 'django.views.generic.create_update.create_object',{'model': Task}), # Uncomment this for admin: (r'^admin/', include('django.contrib.admin.urls')), )
task_list.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>ToDo</title> </head> <body> <p> <a href="/add">新規タスク</a> </p> <h1>Task List</h1> <a href="/">全表示</a> : <a href="/noend">未完了表示</a> <table width="100%" border="1"> <tr> <th nowrap="nowrap">No.</th> <th nowrap="nowrap">タスク</th> <th nowrap="nowrap">状態</th> <th nowrap="nowrap">完了</th> </tr> {% for task in object_list %} <tr> <td>{{ task.task_id }}</td> <td>{{ task.contents }}</td> {% if task.status %} <td>完了</td> <td> </td> {% else %} <td>未完</td> <td><a href="/task_end/{{ task.task_id }}">終わりました</a></td> {% endif %} </tr> {% endfor %} </table> </body> </html>
task_form.html
<!-- Created: 10/03/2007 by char --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN"> <html> <head> <title>Untitled</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <p> <a href="/">タスク一覧</a> </p> <h1>Task Add</h1> <form action="" method="post" enctype="multipart/form-data"> <p><label for="id_contents">タスク名:</label> {{ form.contents }}</p> <input name="" type="submit" class="submit" value="登録" /> </form> <BR> </body> </html>