NullBooleanField is deprecated since Django 3.1 (#71619)

It must be replaced by BooleanField(null=True).
This commit is contained in:
Benjamin Dauvergne 2022-11-23 15:22:07 +01:00
parent 896819fce8
commit 5788e9f0cd
3 changed files with 15 additions and 8 deletions

View File

@ -15,10 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from django.db.models import NullBooleanField
from django.db.models import BooleanField
class UniqueBooleanField(NullBooleanField):
class UniqueBooleanField(BooleanField):
"""BooleanField allowing only one True value in the table, and preventing
problems with multiple False values by implicitely converting them to
None."""
@ -28,10 +28,10 @@ class UniqueBooleanField(NullBooleanField):
kwargs['blank'] = True
kwargs['null'] = True
kwargs['default'] = False
super(NullBooleanField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
def deconstruct(self):
name, path, args, kwargs = super(NullBooleanField, self).deconstruct()
name, path, args, kwargs = super().deconstruct()
del kwargs['null']
del kwargs['blank']
del kwargs['unique']
@ -59,4 +59,4 @@ class UniqueBooleanField(NullBooleanField):
else:
defaults = {'form_class': forms.BooleanField}
defaults.update(kwargs)
return super(NullBooleanField, self).formfield(**defaults)
return super().formfield(**defaults)

View File

@ -13,9 +13,12 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='organizationalunit',
name='user_can_reset_password',
field=models.NullBooleanField(
field=models.BooleanField(
choices=[(None, 'System default'), (True, 'Yes'), (False, 'No')],
verbose_name='Users can reset password',
default=None,
blank=True,
null=True,
),
),
]

View File

@ -126,8 +126,12 @@ class OrganizationalUnit(AbstractBase):
admin_perms = GenericRelation('Permission', content_type_field='target_ct', object_id_field='target_id')
user_can_reset_password = models.NullBooleanField(
verbose_name=_('Users can reset password'), choices=USER_CAN_RESET_PASSWD_CHOICES
user_can_reset_password = models.BooleanField(
verbose_name=_('Users can reset password'),
choices=USER_CAN_RESET_PASSWD_CHOICES,
null=True,
default=None,
blank=True,
)
user_add_password_policy = models.IntegerField(