#guestbook/forms.py # from django.forms import ModelForm, CharField, ValidationError from guestbook.models import Entry class EmptyField(CharField): def clean(self, value): if value!='': raise ValidationError('Please DO NOT fill this field!') class EntryForm(ModelForm): do_not_use=EmptyField(label="Do not fill") def __init__(self, data=None, *args, **kwargs): if data=={}: data=None ModelForm.__init__(self, data, *args, **kwargs) class Meta: model=Entry #guestbook/models.py from django.db import models from django.contrib import admin class Entry(models.Model): nick=models.CharField(max_length=50) url=models.URLField(blank=True) date=models.DateTimeField(auto_now_add=True) text=models.TextField() try: admin.site.register(Entry) except admin.sites.AlreadyRegistered: pass #guestbook/views.py from django.shortcuts import render_to_response from guestbook.models import Entry from guestbook.forms import EntryForm def guestbook(request): form=EntryForm(request.POST) if form.is_valid(): form.save() entries=Entry.objects.all().order_by("-date") templates={'form': form, 'entries': entries} return render_to_response("gbook.html", templates) #guestbook/templates/gbook.html {% extends "base.html" %} {%block content%}