Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview not working #32

Closed
jdhurwitz opened this issue Jul 24, 2018 · 7 comments
Closed

Preview not working #32

jdhurwitz opened this issue Jul 24, 2018 · 7 comments

Comments

@jdhurwitz
Copy link

jdhurwitz commented Jul 24, 2018

Instead of getting a preview, it just looks exactly like the raw text in the editor box.

models.py:

class Question(models.Model, HitCountMixin):
    title = models.CharField(max_length=200, blank=False)
    description = MartorField()

forms.py

class QuestionForm(forms.ModelForm):
    class Meta:
        model = Question
        fields = ['title', 'description']
        widgets = {
            'description': AdminMartorWidget,
        }
    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user')
        super(QuestionForm, self).__init__(*args, **kwargs)
        self.fields['description'] = MartorFormField()

EDIT
My new form looks like this:

class QuestionForm(forms.ModelForm):
    class Meta:
        model = Question
        fields = ['title', 'description']

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user')
        super(QuestionForm, self).__init__(*args, **kwargs)
        self.fields['description'] = MartorFormField()

image

@agusmakmun
Copy link
Owner

I think you should choose one of the existing methods, not using it together.
You can see this DEMO for the refference.

@jdhurwitz
Copy link
Author

@agusmakmun What do you mean existing methods?

@jdhurwitz
Copy link
Author

If I remove the self.fields['description'] call, the behavior persists.

@agusmakmun
Copy link
Owner

  1. If you want to use this markdown editor for /admin/ (Django Administration) and outside it. you can only use it on models
from django.db import models
from martor.models import MartorField

class Question(models.Model, HitCountMixin):
    title = models.CharField(max_length=200, blank=False)
    description = MartorField()
  1. If you want to show this markdown editor only for your /admin/ (Django Administration), you can use this in your file admin.py:
from django.db import models
from django.contrib import admin

from martor.widgets import AdminMartorWidget
from yourapp.models import Question

class QuestionAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': AdminMartorWidget},
    }

admin.site.register(Question, QuestionAdmin)
  1. But, if you only want to show this markdown editor outside /admin/ (Django Administration). you can use this:
class QuestionForm(forms.ModelForm):
    class Meta:
        model = Question
        fields = ['title', 'description']

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user')
        super(QuestionForm, self).__init__(*args, **kwargs)
        self.fields['description'] = MartorFormField()

@jdhurwitz
Copy link
Author

jdhurwitz commented Jul 25, 2018

I've edited my QuestionForm to resemble option 3, and preview still does not work. It displays the exact same text as before.

@agusmakmun
Copy link
Owner

Have you loaded the CSS & JS files?

  <link href="{% static 'plugins/css/ace.min.css' %}" type="text/css" media="all" rel="stylesheet" />
  <link href="{% static 'plugins/css/semantic.min.css' %}" type="text/css" media="all" rel="stylesheet" />
  <link href="{% static 'plugins/css/resizable.min.css' %}" type="text/css" media="all" rel="stylesheet" />
  <link href="{% static 'martor/css/martor.min.css' %}" type="text/css" media="all" rel="stylesheet" />

and

  <script type="text/javascript" src="{% static 'plugins/js/ace.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/semantic.min.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/mode-markdown.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/ext-language_tools.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/theme-github.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/resizable.min.js' %}"></script>
  <script type="text/javascript" src="{% static 'plugins/js/emojis.min.js' %}"></script>
  <script type="text/javascript" src="{% static 'martor/js/martor.min.js' %}"></script>

@jdhurwitz
Copy link
Author

Forgot to do that! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants