I have two simple models Question and Choice (one question has multiple choices). I have used inline formset to add Choices along with adding Questions (through modelAdmin functionality).
class Question(models.Model):
category = models.CharField(max_length=50)
question_text = RichTextField(max_length=2000, verbose_name="Question Text", blank=True)
class Choice(models.Model):
question = models.ForeignKey(Question)
description = RichTextField(max_length=500, verbose_name="Choice Description")
is_correct = models.BooleanField(default=False)
Now the fields of Choice and Question are RichTextField defined in django-ckeditor. The issue is when I click on "Add another choice" I get an uncaught exception: [CKEDITOR.editor] The instance "id_choice_set-__prefix__-description" already exists
, which disrupts the ckeditor functionality.
Any ideas/suggestions how to fix this issue? I think some JS tweaks can help but I have a very limited knowledge in JS/Jquery
Thanks
I encountered similar issue and found a fix here.
It's caused by Inline usage,try install the forked version to have try.
Though 6 months pass,hope this help those who got similar issue.
Line 66 of django-ckeditor's widgets.py is where your problems seems to originate.
Essentially it seems, the substitution made for final_attr['id']
is where you are getting the __prefix__
from. Looking through the framework source code, line 151 of Django's forms/formsets.py is where that value comes from. Also, from the source, it seems that value will be replaced by the default prefix i.e. 'form' in all cases except if you are using _get_empty_form()
incorrectly somehow.
It would be helpful if you provide/answer the following:
Once your page is rendered, but before you "Add another choice", post the tag attributes from your rendered formset (incl. the management form).
Are you using _get_empty_form()
directly at any point in your code?
Code for the view where you create the formset and where you render it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With