Search code examples
djangomarkdowndjango-widget

The django-markdown-bootstrap-widget is not showing properly


I am django beginner and I have the following Problem. I want to define a model and us this model to generate a form with the markdown-widget. https://github.com/MSA-Argentina/django-bootstrap-markdown

Model

class ThesisAnmeldung(models.Model):
    forschungsfrage = models.CharField(max_length=500)
    def __str__(self):
        return self.forschungsfrage

Form

class Thesis(ModelForm):
    name = forms.CharField(widget= MarkdownEditor(attrs={'id': 'content','height': 150, } ))
    name2 = forms.CharField(widget= MarkdownEditor(attrs={'id': 'content2','height': 150, } ))#
    class Meta:
        model = ThesisAnmeldung
        fields = ('forschungsfrage',)
        widgets = {'name': MarkdownEditor(attrs={'id': 'content3','height': 150, } ) , } 

Problem name and name2 are displayed correctly with the markdown-editor. Only the third field forschungsfrage shows the problem. i can only see a small standard textbox. It seems like the markdown-widget is not used. Is there any solution for this problem?

Picture


Solution

  • Where do you set forschungsfrage to use markdown? You may overwrite that field in form as well.

    class Thesis(ModelForm):
        name = forms.CharField(widget= MarkdownEditor(attrs={'id': 'content','height': 150, } ))
        name2 = forms.CharField(widget= MarkdownEditor(attrs={'id': 'content2','height': 150, } ))#
        forschungsfrage = forms.CharField(widget= MarkdownEditor(attrs={'id': 'forschungsfrage','height': 150, } ))
    
        class Meta:
            model = ThesisAnmeldung
            fields = ('forschungsfrage',)