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

  • Home
  • SEARCH
  • 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 7588821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:01:07+00:00 2026-05-30T20:01:07+00:00

How can I have field dependency? Case 1: If boolean field call_me is set,

  • 0

How can I have field dependency?

Case 1: If boolean field call_me is set, then telephone must be set, else it should be blank

Case 2: If many to many field category (with values sale, rent) has one of the values as sale, then price_sale must be set, else it should be blank

  • 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-30T20:01:09+00:00Added an answer on May 30, 2026 at 8:01 pm

    For Case 1, you can validate that easily in the model’s clean method:

    from django.core.exceptions import ValidationError
    
    class MyModel(models.Model):
         ...
         def clean(self):
             if self.call_me and not self.telephone.strip():
                 raise ValidationError('Telephone is required')
    

    For Case 2, M2M relationships are not added until after the model is saved, so using clean on your model won’t work in this scenario. However, you can do this from the clean method of any ModelForm you use to edit this, be it in the admin or your own view.

    However, having category as a M2M when the only possible values are “sale” and “rent”, is poor design. Even then, “sale” and “rent” are mutually exclusive, so an M2M is inappropriate anyways (your model won’t be experiencing both a “sale” and a “rent” at the same time ever).

    As a result, it would be a better idea to have category be a CharField with choices consisting of “sale” and “rent”. If you do it that way, you can then use your model’s clean method in the same way as Case 1 for this as well.

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

Sidebar

Related Questions

I have a strange problem which I can't fix: A field: private boolean[][][] gaps;
I have a field 'Description' which can have product descriptions with any unicode characters.
I have form where user submits field. Field can have letters, numbers, and punctuation.
I have a phone number field that can have lots of different characters such
I have a (varchar) field Foo which can only be specified if (bit) Bar
I have an input field where both regular text and sprintf tags can be
If I have a text field with SWT, how can I get the field
I have a table with one field that can point to a foreign key
I have an input edit field where the user can enter data. I want
Summary: Every field rows of detailsview have 2 td and their first td can

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.