Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean setting with initial value set to False is breaking the system #13

Open
munhitsu opened this issue Dec 13, 2010 · 1 comment
Open

Comments

@munhitsu
Copy link

It seems that either "val.initial = val.clean(val.initial)" is django overuse or there is an issue with django since quite long for BooleanField.
Meanwhile it might be useful not to use val.clean for BooleanField.

class BooleanField(Field):
widget = CheckboxInput

def to_python(self, value):
    """Returns a Python boolean object."""
    # Explicitly check for the string 'False', which is what a hidden field
    # will submit for False. Also check for '0', since this is what
    # RadioSelect will provide. Because bool("True") == bool('1') == True,
    # we don't need to handle that explicitly.
    if value in ('False', '0'):
        value = False
    else:
        value = bool(value)
    value = super(BooleanField, self).to_python(value)
    if not value and self.required:
        raise ValidationError(self.error_messages['required'])
    return value

To reproduce issue create appsettings group:
@register
class Offer:
as_download = False

@aasmpro
Copy link

aasmpro commented Aug 25, 2021

@munhitsu take a look at django-zero-settings too, that may help you in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants