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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:53:32+00:00 2026-06-03T17:53:32+00:00

I have a Django model and from. class Settings(models.Model): field_1 = models.BooleanField() field_2 =

  • 0

I have a Django model and from.

class Settings(models.Model):
    field_1 = models.BooleanField()
    field_2 = models.CharField(max_length = 255)

and the form

class SiteSettingsForm(forms.ModelForm):
    class Meta:
        model = SiteSettings

I have an HTML form, and when the checkbox for the Boolean field_1 is not checked, then the 2nd field (field_2) is disabled.

The problem is that, if I try and save the form, it says that there is an error, because field_2 is empty.

I want that, if the field_2 is not disabled and is not empty, to get the error but if field_2 is disabled, I want the form to take the value from the database.

I have tried this:

class SettingsForm(forms.ModelForm):
    class Meta:
        model = Settings

    def __init__(self, *args, **kwargs):
        super(SettingsForm, self).__init__(*args, **kwargs)

    def clean(self):
        field_1 = self.data.get('field_1','')
        if not field_1:   # field_2 is disabled 
            self.data['field_2'] = self.instance.field_2 # so get from db
        super(SettingsForm, self).clean()
        return self.cleaned_data

The problem is that I get an error:

This QueryDict instance is immutable

  • 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-03T17:53:33+00:00Added an answer on June 3, 2026 at 5:53 pm

    Change your form for it:

    class SettingsForm(forms.ModelForm):
        class Meta:
            model = Settings
    
        def __init__(self, *args, **kwargs):
            super(SettingsForm, self).__init__(*args, **kwargs)
    
        def clean(self):
            cleaned_data = super(SettingsForm, self).clean()
            field_1 = cleaned_data.get('field_1','')
            if not field_1:   # field_2 is disabled 
                cleaned_data['field_2'] = self.instance.field_2 # so get from db
            self.cleaned_data = cleaned_data
            return self.cleaned_data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Account model in Django. class Account(models.Model): name = CharField(max_length=255) description = CharField(max_length=500)
I have a basic Django model like: class Business(models.Model): name = models.CharField(max_length=200, unique=True) email
I have a django model like this: class Player(models.Model): name = models.CharField() batting =
I have a model: class Server(models.Model): serverId = models.IntegerField(verbose_name=_(serverId)) name = models.CharField(max_length=200, verbose_name=_(server_name)) ip
I have the following django model: RESOURCE_DIR = os.path.join(settings.MEDIA_ROOT, 'resources') class Resource(models.Model): title =
I have a form like so: from django import forms from django.contrib.auth.models import User
If I have a Django model with a FileField e.g., class Probe(models.Model): name =
Say I have django model that looks something like this: class Order(models.Model): number =
I have the following models: http://slexy.org/view/s20T8yOiKZ from mxutils.cms_services import generate_secid from django.db import models
I have the following models in my Django app. How can I from the

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.