From fc0ab4052182336bf92a6254e550532f7788d1a5 Mon Sep 17 00:00:00 2001 From: agenteAND <44445475+agenteAND@users.noreply.github.com> Date: Thu, 10 Jun 2021 15:26:31 -0400 Subject: [PATCH] Fix AttributeError: 'max_length' unsing template_choices when use template_choices raise AttributeError: 'GrapesJsHtmlField' object has no attribute 'max_length', beacuse `super().__init__(*args, **kwargs)` is call after line: `if self.check_template_choices(template_choices):` --- django_grapesjs/models/fields.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_grapesjs/models/fields.py b/django_grapesjs/models/fields.py index 22d0f19..01288a6 100644 --- a/django_grapesjs/models/fields.py +++ b/django_grapesjs/models/fields.py @@ -15,8 +15,9 @@ class GrapesJsHtmlField(models.TextField): Model field with support grapesjs. """ - def __init__(self, default_html=GRAPESJS_DEFAULT_HTML, redactor_config=BASE, + def __init__(self, *args, default_html=GRAPESJS_DEFAULT_HTML, redactor_config=BASE, apply_django_tag=False, validate_tags=False, template_choices=None, **kwargs): + super().__init__(*args, **kwargs) if kwargs.get('choices'): raise ValueError( "use 'template_choices' instead of 'choices' in the '%s'" % self.__class__.__name__ @@ -35,7 +36,7 @@ def __init__(self, default_html=GRAPESJS_DEFAULT_HTML, redactor_config=BASE, 'widget': GrapesJsWidget, } - super().__init__(**kwargs) + def formfield(self, **kwargs): return super().formfield(**{**kwargs, **self.params_for_formfield}) @@ -45,7 +46,7 @@ def check_template_choices(self, value): return False self.choices = value - error = self._check_choices() + error = super()._check_choices() if error: error_info = error[0].msg.replace('choices', 'template_choices')