Add deconstruct method for LocalizedBleachField for it to be recognized in django migrations

This commit is contained in:
GRazvan12 2024-01-23 17:32:42 +02:00 committed by Swen Kooij
parent fbc1eec754
commit 463c415be2

View File

@ -9,6 +9,8 @@ class LocalizedBleachField(LocalizedField):
"""Custom version of :see:BleachField that is actually a """Custom version of :see:BleachField that is actually a
:see:LocalizedField.""" :see:LocalizedField."""
DEFAULT_SHOULD_ESCAPE = True
def __init__(self, *args, escape=True, **kwargs): def __init__(self, *args, escape=True, **kwargs):
"""Initializes a new instance of :see:LocalizedBleachField.""" """Initializes a new instance of :see:LocalizedBleachField."""
@ -16,6 +18,14 @@ class LocalizedBleachField(LocalizedField):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def deconstruct(self):
name, path, args, kwargs = super().deconstruct()
if self.escape != self.DEFAULT_SHOULD_ESCAPE:
kwargs["escape"] = self.escape
return name, path, args, kwargs
def pre_save(self, instance, add: bool): def pre_save(self, instance, add: bool):
"""Ran just before the model is saved, allows us to built the slug. """Ran just before the model is saved, allows us to built the slug.