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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:23:12+00:00 2026-05-27T14:23:12+00:00

Being a Django newbie, I have a question to ask, which should be very

  • 0

Being a Django newbie, I have a question to ask, which should be very simple, but I just can’t figure it out:

I have created a model like the one below:

from django.db import models
from django.core.exceptions import ValidationError

def validate_case_id(value):
    if value != "testing":
        raise ValidationError("type testing")

class case_form3_tb(models.Model):
    case_id = models.CharField(max_length=20, blank=True, null=True, verbose_name="Case ID", validators=[validate_case_id])
    wound_others = models.BooleanField(verbose_name="Others")
    wound_others_desc = models.CharField(max_length=200, blank=True, null=True, verbose_name="Others (Description)")    

I want to validate it in a way that if wound_others is ticked, then wound_others_desc must not be blank.

I just learn how to validate one single text field, but what if the text field is validated based on some other fields?

Thanks.

  • 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-27T14:23:12+00:00Added an answer on May 27, 2026 at 2:23 pm

    You should validate at the model level, i.e., write a clean() method for the model:

    def clean(self):
        from django.core.exceptions import ValidationError
        if self.wound_others and not self.wound_others_desc:
            raise ValidationError('Description must not be blank.')
    

    As a side note, the model name you chose is heavily anti-pythonic. You should always follow the CapWords convention for Python class names.

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

Sidebar

Related Questions

Typically in Django I can find out what queries are being run against the
I have a rather simple informational website that's being run by Django. Its' pages(views)
I have a a django application which is being served from apache/mod_wsgi under www.mysite.com/mysite
a newbie django question I want to use 3rd party app, but I need
I have a website that is being served by nginx and django. My staging.py
I have django tinymce setup but I hav noticed an issue with the tool
In a django application I am working on, I have just added the ability
I have a nice and lovely Django site up and running, but have noticed
I have created a Django app. I have a registration page(simple HTML form) in
I'm trying to setup celery and django, but the celery_taskmeta table is not being

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.