WORKON_HOME=~/Envs source /usr/local/bin/virtualenvwrapper.sh then edit your .profile on osx or .bashrc on linux and add the following lines: reload your .profile or .bashrc files: $ . ~/.profile
development server: $ cd quickstart $ python manage.py runserver ... Development server is running at http:// 127.0.0.1:8000/ Quit the server with CONTROL-C.
... Would you like to create one now? (yes/no): yes Username (leave blank to use 'marconi'): E-mail address: [email protected] Password: Password (again): Superuser created successfully. Installing custom SQL ... Installing indexes ... Installed 0 object(s) from 0 fixture(s)
import Todo 3 4 class TodoForm(forms.ModelForm): 5 class Meta: 6 model = Todo 7 fields = ('name',) 8 9 class TodoListForm(forms.Form): 10 def __init__(self, *args, **kwargs): 11 todos = kwargs.pop('todos', []) 12 super(TodoListForm, self).__init__(*args, **kwargs) 13 for todo in todos: 14 field = str(todo.id) 15 self.fields[field] = forms.BooleanField( 16 required=False, label=todo.name) 17 self.fields[field].is_done = todo.is_done 18 19 def clean(self): 20 selected = [tid for tid, val in self.cleaned_data.items() if val] 21 if not selected: 22 raise forms.ValidationError("You need to select one or more items.") 23 return selected $ vim todo/forms.py
from django.template import RequestContext 3 from django.contrib import messages 4 5 from todo.forms import TodoListForm, TodoForm 6 from todo.models import Todo ...