I would like to create TodayOrLaterDateField() which would subclass DateField() field as I am using this condition in many places. The purpose of this field would be avoiding pu
You can extend models.DateField
and override to_python
method. Didn't tested on Django 1.3 but should work.
import datetime
from django.core import exceptions
from django.db import models
class TodayOrLaterDateField(models.DateField):
def to_python(self, value):
value = super(TodayOrLaterDateField, self).to_python(value)
if value < datetime.date.today():
raise exceptions.ValidationError(u'Date must be today or later')
return value