Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6965523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:04:20+00:00 2026-05-27T16:04:20+00:00

I am very new to Django. I am working on a small project in

  • 0

I am very new to Django. I am working on a small project in which I am using ModelForm.
For the date field, I want to do custom validation i.e. whenever a user enters a date before today’s date it should display an error message near the date field. I have written code as per Django’s documentation, but it gives ValidationErrors for the raise statement in model form. like below:

ValidationError at /add_task/
[u"Please enter valid date. Either today's date or after that."]

Please help me how to overcome this problem. Thanks in advance.

models.py

from django.db import models

class MyTask(models.Model):
    summary=models.CharField(max_length=100)
    description=models.CharField(max_length=500)
    due_date=models.DateField(null=True)
    completed_status=models.BooleanField()
    
    def __unicode__(self):
        return self.summary

forms.py

from django.forms import ModelForm, Textarea
from django.forms.extras.widgets import SelectDateWidget
from django.core.exceptions import ValidationError
from assignment.models import MyTask

import datetime

class AddTaskForm(ModelForm):

    class Meta:
        model=MyTask
        fields=('summary','description','due_date')
        widgets = {
            'description': Textarea(attrs={'cols': 50, 'rows': 10}),
            'due_date':SelectDateWidget(),
        }
        
    def get_due_date(self):
        diff=self.cleaned_data['due_date']-datetime.date.today()
        if diff.days<0:
            raise ValidationError("Please enter valid date. Either today's date or after that.")
        else:
            return self.cleaned_data['due_date']    
    
    def get_summary(self):
            return self.cleaned_data['summary']


    def get_description(self):
            return self.cleaned_data['description']

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:04:20+00:00Added an answer on May 27, 2026 at 4:04 pm

    Your validation method needs to be called clean_due_date. In Django < 3 it should raise forms.ValidationError, but in Django 3 it should use core.exceptions.ValidationError.

    I have no idea what the get_summary and get_description methods are for, they aren’t called and don’t do anything useful.

    See the Django 3 docs here and the Django 2 docs here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im creating a webapplication in django to which Im very new. what I want
I am evaluating using CouchDB in my new Django-project. Is there a good database
Maybe this is a very silly question but I'm new using django. I have
I'm very new to django, about a week into it. I'm making a site
Very new to python and can't understand why this isn't working. I have a
Very new to using Raphael.js I'm looking at the tutorials and I am able
I am very new to django and I have a problem on how to
I am very new to Python/Django and programming in general. With the limited tools
After working through the Django tutorial I'm now trying to build a very simple
I'm very new to Django, having never developed on it. I'm trying to develop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.