from django import forms import datetime class NoticeForm(forms.Form): date_formats = ['%d.%m.%Y', '%d.%m.%y'] title = forms.CharField(label='Titel', max_length=80) text = forms.CharField(label='Text', max_length=400) start = forms.DateField(label='Von', input_formats=date_formats, initial=datetime.date.today) end = forms.DateField(label='Bis', input_formats=date_formats, initial=datetime.datetime.today() + datetime.timedelta(days=1)) class EditNoticeForm(forms.Form): def __init__(self, *args, **kwargs): self.title = forms.CharField(label='Titel', max_length=80, initial=kwargs.pop('notice_title')) self.text = forms.CharField(label='Text', max_length=400, initial=kwargs.pop('notice_text')) self.start = forms.DateField(label='Von', initial=kwargs.pop('notice.pub_start'), input_formats=NoticeForm.date_formats) self.end = forms.DateField(label='Bis', initial=kwargs.pop('pub_end'), input_formats=NoticeForm.date_formats) super(EditNoticeForm, self).__init__(*args, **kwargs)