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 8530969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:22:37+00:00 2026-06-11T09:22:37+00:00

I am new to Django and somewhat confused regarding the validation steps during form

  • 0

I am new to Django and somewhat confused regarding the validation steps during form processing. I am aware that all form field types (in my case a ModelForm) are required by default. I assumed that Django would raise a VaidationError in case a required form field was left blank without calling the form’s clean method.

This is why I did not check if any data was set in the following clean() method:

def clean(self):
    date =  self.cleaned_data.get('date')
    time_start = self.cleaned_data.get('time_start')
    time_end = self.cleaned_data.get('time_end')
    user_type = self.cleaned_data.get('user_type')

    if Event.objects.filter(user_type=user_type, date=date, 
                            time_start__lt=time_start, 
                            time_end__gt=time_start).exclude(pk=self.instance.pk).count():
        raise forms.ValidationError("Overlapping with another event.")

Submitting the form while leaving all fields blank causes a

ValueError: Cannot use None as a query value.

If I remove my clean() method I will get the expected ValidationErrors for not filling out the required fields – which is what I expected with the clean() method still in place.

Any idea what could cause this to happen? I would be surprised if Django does not check for required values before it calls clean.

  • 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-06-11T09:22:38+00:00Added an answer on June 11, 2026 at 9:22 am

    This is strange because the validation of the fields is performed before the calling of the form’s clean method. Moreover an error raised from a field is stored in form.my_field.errors while the errors returned from the form’s clean method are accumulated in form.non_field_errors.

    Below is the order of the validations performed in a form:

    full_clean()
        |
    Field clean() [field's built-in clean method]
        |
    Form clean_*() [custom validation method for field]
        |
    Form clean() [form's clean method]
        |
    cleaned_data/errors
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new to django and trying to make a user registration form with few
I have an existing PostgreSQL database that I'm using for a new Django site.
These are the steps I've done: Create a virtual env Create a new Django
I'm a somewhat new to python and was looking through the Django source code.
I'm new to django and had a question regarding organizing views. manage.py startapp creates
I have a new Django 1.3 project and app that I've created. I added
New to Django so it's probable I'm doing this all wrong. I have an
I'm somewhat new to Python, Django, and I'd like some advice on how to
I am somewhat new to Django and have searched for some simple examples of
Let's assume that you are working at the first version of a new Django

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.