How to create a ModelForm instance with the child model record as a key to perform UpdateView on a modal form in DetailView

Introduction

I’m developing an article publishing application in Django.And I’m developing a function to edit comments on articles using Bootstrap modal forms.

Premise

The models are CustomUser for user information, Article for articles, and Comment for comments, with the following relationship.

from mdeditor.fields import MDTextField

class CustomUser(AbstractUser):

    username = models.CharField(
        _("username"),
        max_length=30,
        help_text='Required 30 characters or fewer.',
        unique=True,
        error_messages={
            'unique': _("This Username already exists."),
        },)

    email = models.EmailField(
        _('email'),
        unique=True,
        error_messages={
            'unique': _("A user with that email address already exists."),
        },)
    
    class Meta:
        verbose_name_plural = 'CustomUser'

class Article(models.Model):

    post_user = models.ForeignKey(CustomUser, verbose_name='Post User', on_delete=models.CASCADE, related_name='name',)
    title = models.CharField(verbose_name='title', max_length=50,)
    content = MDTextField()
    created_at = models.DateField(verbose_name='created_at', auto_now_add=True,)

    class Meta:
        verbose_name_plural = 'Article'

    def __str__(self):
        return self.title

class Comment(models.Model):
 
    writer = models.ForeignKey(CustomUser, on_delete=models.CASCADE,)
    text = MDTextField()
    target = models.ForeignKey(Article, on_delete=models.CASCADE,)
    created_at = models.DateField(verbose_name='created_at', auto_now_add=True,)
    updated_at = models.DateField(verbose_name='updated_at', auto_now=True,)

    def __str__(self):
        return self.text[:20]

The requirements for the article detail page (article_detail.html) where the comment edit function is to be placed are as follows.

・Display the contents of the article (DetailView)
・Display comments on the article
・Set up an input form for comments.
・Provide a pull-down menu for each comment with a link to edit/delete the comment.
・A modal window is displayed when a link in the pull-down menu is pressed, and the comment can be edited/deleted on that window.

The ArticleDetailView is used to display the article detail page, while the list of comments, comment input form, and comment edit form are prepared by overriding get_context_data(). Also, the View for edit comments is done in CommentUpdateView, but since it is done in a modal window, no template for edit comments is prepared.

class ArticleDetailView(generic.DetailView):
    model = Article
    template_name = 'article_detail.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        #comment creation form
        context['form'] = CommentCreateForm()

        #comment editing form
        comment = Comment.objects.get(article__target=self.object)
        context['comment_form'] = CommentCreateForm(instance=comment)

        #comment list
        context['comment_list'] = Comment.objects.select_related('target').filter(target=self.kwargs['pk'])

        return context

class CommentUpdateView(generic.UpdateView, LoginRequiredMixin):
    model = Comment
    form_class = CommentCreateForm
    template_name = 'article_detail.html'

    def get_success_url(self):
        article = Article.objects.get(comment__pk=self.kwargs['pk'])
        return reverse_lazy('article:article_detail', kwargs={'pk': article.pk})

    def form_valid(self, form):
        messages.success(self.request, 'Your comment has been successfully updated.')
        return super().form_valid(form)

    def form_invalid(self, form):
        messages.error(self.request, 'Failed to correct comment.')
        return super().form_invalid(form)

The model form, routing, and template (only the part related to the modal for comment edit) are as follows.

class CommentCreateForm(forms.ModelForm):
    class Meta:
        model = Comment
        fields = ("text",)
app_name = 'article'

urlpatterns = [
    path('article_detail/<int:pk>', views.ArticleDetailView.as_view(), name='article_detail'),
    path('<int:pk>/comment/update', views.CommentUpdateView.as_view(), name='comment_update'),
]
{% if comment_list %}
    <section class="comment-list">
      <h2 id="comments" class="comment-title"><i class="fa-regular fa-comments"></i> comment</h2>
      {% for comment in comment_list %}
            {% if user ==  comment.writer %}
            <ul class="navbar-nav">
              <li class="nav-item dropdown">
                <a class="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <img class="rounded-circle u-box-shadow-sm mr-2" width="25" height="25" src="{% static 'img/three_dots_icon.png' %}" alt="Icon">
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                  <a class="dropdown-item" id="showModal" data-toggle="modal" data-target="#commentModal-{{ comment.pk }}">Edit</a>                                   
                  <a class="dropdown-item" id="showModal2" data-toggle="modal" data-target="#deleteModal-{{ comment.pk }}">Delete</a>
                </div>

                <!-- Comment Edit Modal Dialog -->
                <div class="modal fade bd-example-modal-lg" id="commentModal-{{ comment.pk }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                  <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Modify Your Comment</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <form class="text-center w-md-75 mx-auto" method="POST" enctype="multipart/form-data" action="{% url 'article:comment_update' comment.pk %}">
                          {% csrf_token %}
                          {{ form.non_field_errors }}
                          {{ form.media }}

                          {% for field in comment_form %}                        
                          <div class="col-xl-12 form-group mb-4">
                            {{ field|markdown }}
                            {{ field.errors }}
                          </div>
                          {% endfor %}
                        </form>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-lg btn-primary py-3 px-4" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-lg btn-primary py-3 px-4">Save changes</button>
                      </div>
                    </div>
                  </div>
                </div>
              </li>
            </ul>
            {% endif %}

          <div class="comment-content">
            <p>{{ comment.text|markdown|safe }}</p>
          </div>
          <div class="reply">
            <a class="comment-reply-link" href="#"><span class="fa fa-comment-o"></span> Reply</a>
          </div>
        </div>
        </li>
      </div>
      {% endfor %}
    </section>
    {% endif %}

Issues

I got a FieldsError in my browser.

According to Traceback, it seems to be failing to create an instance of CommentCreateForm.

#views.py-ArticleDetailView()-get_context_data()

#comment editing form
        comment = Comment.objects.get(article__target=self.object)
        context['comment_form'] = CommentCreateForm(instance=comment)

I would like to use get_context_data() in ArticleDetailView to capture the comments to be edited and create a CommentCreateForm() instance based on that information.

I was wondering if it would be correct to use the CommentUpdateView to capture the comments to be edited, instead of using the methods in ArticleDetailView to do so. In any case, I have no idea how to capture the comment to be edited and set up an instance of it.

There is a problem at:

This expression is saying that you’re looking for a field named article and are going to use it as a reference to find a field named target.

The error message is telling you that you do not have a field named article in Comment.

In the Comment model you have:

The field appears to be named target.

It’s not clear to me what you’re specifically trying to retrieve with that query, so I’m not sure I can suggest a specific solution yet.
ArticleDetailView is a CBV on the model Article, which means there might be many Comment referring to self.object. A get is going to fail as soon as an Article has a second Comment referring to it.

1 Like

Thank you for your comment.

As you say, I think this part is wrong. But I’m not sure how to specify the query.

What I want to do in this part is to extract the query of the comment to be edited in the modal window.

Then,using this query, I’m going to make an instance of CommentCreateForm() and pass it to the template as context data to edit the comment in the modal window in article_detail.html.

But which comment? You may have multiple comments associated with an article.

If the user is selecting a comment in the browser, then you would want a separate view to (possibly) query on the selected comment and render the form for the modal block.

1 Like

That’s the comment selected by the requesting user.The image below shows the edit modal window of the comment selected by the requesting user.

I think it’s CommentUpdateView. This View is called from a modal window in template <form method="POST" enctype="multipart/form-data" action="{% url 'article:comment_update' comment.pk %}">.Even with this view, the comment to be edited does not appear as shown in the image and does not work.

class CommentUpdateView(generic.UpdateView, LoginRequiredMixin):
    model = Comment
    form_class = CommentCreateForm
    template_name = 'article_detail.html'

    def get_success_url(self):
        article = Article.objects.get(comment__pk=self.kwargs['pk'])
        return reverse_lazy('article:article_detail', kwargs={'pk': article.pk})

    def form_valid(self, form):
        messages.success(self.request, 'Your comment has been successfully updated.')
        return super().form_valid(form)

    def form_invalid(self, form):
        messages.error(self.request, 'Failed to correct comment.')
        return super().form_invalid(form)

You do not POST to a view when you want to get a form to be displayed. You issue a GET to a view to get the form. The POST is used to submit the updated data in the form to that view.

1 Like

Thank you for pointing this out.

I tried changing the method option to GET, but as you can see in the image, only the markdown editor is displayed, but the comment to be edited is not displayed, and when I press the “Save Change” button, it does not redirect to the page specified in reverse_lazy().

<div class="modal fade bd-example-modal-lg" id="commentModal-{{ comment.pk }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                  <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Modify Your Comment</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <form class="text-center w-md-75 mx-auto" method="GET" enctype="multipart/form-data" action="{% url 'article:comment_update' comment.pk %}">
                          {% csrf_token %}
                          {{ form.non_field_errors }}
                          {{ form.media }}

                          {% for field in form %}                        
                          <div class="col-xl-12 form-group mb-4">
                            {{ field|markdown|safe }}
                            {{ field.errors }}
                          </div>
                          {% endfor %}
                        </form>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-lg btn-primary py-3 px-4" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-lg btn-primary py-3 px-4">Save changes</button>
                      </div>
                    </div>
                  </div>
                </div>
class CommentUpdateView(generic.UpdateView, LoginRequiredMixin):
    model = Comment
    form_class = CommentCreateForm
    template_name = 'article_detail.html'

    def get_success_url(self):
        article = Article.objects.get(comment__pk=self.kwargs['pk'])
        return reverse_lazy('article:article_detail', kwargs={'pk': article.pk})

    def form_valid(self, form):
        messages.success(self.request, 'Your comment has been successfully updated.')
        return super().form_valid(form)

    def form_invalid(self, form):
        messages.error(self.request, 'Failed to correct comment.')
        return super().form_invalid(form)

While probably not the only issue, the first thing I notice here is that:

Your parent classes are in the wrong order. Mixin classes must appear before the base class in a class definition.

1 Like

Thank you for pointing this out. I did not know about that and learned a lot. I have corrected your point, but the situation could not be improved.

There was one other point of concern. When I changed the form tag for comment modification from {{ comment_form }} to {{ form }} in the template, the comment creation form that was originally displayed in markdown input format became like the image.

I thought this was due to the fact that the CommentCreateForm passed in the ArticleDetailView context data and the CommentCreateForm passed in the CommentUpdateView class variable were the same.

So, I changed the ArticleDetailView context data (comment creation form) as follows and changed the template tag of the comment creation form from {{ form }} to {{ comment_form }}, but the situation still remains as shown in the image.

context['comment_form'] = CommentCreateForm()

First, let’s try to keep a couple things separated here.

It’s my understanding that we’re trying to resolve an issue with the form being generated by your CommentUpdateView as it is being displayed as a modal.

The process, templates, and forms involved with this have nothing to do with the parent page in which this is used. There is no direct correlation or relationship between the two beside the fact that a button on one causes the other view to be executed and its template to be rendered.

Now, having said that -

Here’s the reverse of the problem resolved earlier. You do want to POST this form to submit the data from the form to the view in order for the data to be saved.

Now, your view for CommentUpdateView has these attributes:

This means that by default, the view is going to create a context variable named form containing an instance of CommentCreateForm, which you have defined as:

So it appears to me that the picture you posted for that form is exactly what should be appearing for the comment.

1 Like

Thank you for clarifying what needs to be discussed.

Yes. To be more specific, the goal is to allow comments selected by the requesting user to be edited in the modal by CommentUpdateView

I’d like to ask you 2 things.

The first thing is about

I now understand how this works.
In this case, the template(article_detail.html) receives 2 CommentCreateForm() instances.(One is from ArticleDetailView, the other is from CommentUpdateView) .
The CommentCreateForm() instance from ArticleDetailView is rendered when user access article detail page, while the CommentCreateForm() instance from CommentUpdateView is rendered when the “Edit” button is pressed, which triggers the display of a modal window.

In article_detail.html, template variable {{ form }} is set in two places, one for creating comments and the other for editing comments.

{% for comment in comment_list %}
<div class="commets-list">
  <li class="comment even thread-even depth-1 parent" id="comment-18730" style="list-style:none">
    <div id="div-comment-18730" class="comment-body article">

      {% if user ==  comment.writer %}
      <ul class="navbar-nav">
        <li class="nav-item dropdown">
          <a class="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <img class="rounded-circle u-box-shadow-sm mr-2" width="25" height="25" src="{% static 'img/three_dots_icon.png' %}" alt="Icon">
          </a>
          <!-- Modal Triger -->
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
            <a class="dropdown-item" id="showModal" data-toggle="modal" data-target="#commentModal-{{ comment.pk }}">Edit</a>                                   
            <a class="dropdown-item" id="showModal2" data-toggle="modal" data-target="#deleteModal-{{ comment.pk }}">Delete</a>
          </div>

          <!-- Comment Edit Modal Form -->
          <div class="modal fade bd-example-modal-lg" id="commentModal-{{ comment.pk }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title" id="exampleModalLabel">Modify Your Comment</h5>
                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                </div>
                <div class="modal-body">
                  <form class="text-center w-md-75 mx-auto" method="POST" enctype="multipart/form-data" action="{% url 'article:comment_update' comment.pk %}">
                    {% csrf_token %}
                    {{ form.non_field_errors }}
                    {{ form.media }}

                    {% for field in form %}                        
                    <div class="col-xl-12 form-group mb-4">
                      {{ field|markdown|safe }}
                      {{ field.errors }}
                    </div>
                    {% endfor %}
                  </form>
                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-lg btn-primary py-3 px-4" data-dismiss="modal">Cancel</button>
                  <button type="submit" class="btn btn-lg btn-primary py-3 px-4">Save changes</button>
                </div>
              </div>
            </div>
          </div>
        </li>
      </ul>
      {% endif %}
    <div class="comment-content">
      <p>{{ comment.text|markdown|safe }}</p>
    </div>
    <div class="reply">
      <a class="comment-reply-link" href="#"><span class="fa fa-comment-o"></span> Reply</a>
    </div>
  </div>
  </li>
</div>
{% endfor %}

<!-- Comment Create Form -->
{% if user.is_authenticated %}
<h2 class="h1" style="justify-content: center; margin-top: 6rem;">Comment</h2>
  <form method="POST" action="{% url 'article:comment_create' article.pk %}">
  {% csrf_token %}
  {{ form.non_field_errors }}
  {{ form.media }}

  {% for field in form %}
  <div class="row" style="justify-content: center;">
    <div class="col-xl-12 form-group mb-4">
        {{ field|markdown|safe }}
        {{ field.errors }}
    </div>
  </div>
  {% endfor %}
  <div class="text-center">
    <button class="btn btn-lg btn-primary py-3 px-4" type="submit" style="margin-bottom: 2rem;">Comment</button>
  </div>  
</form>
{% endif %}

In my understanding, There is no direct correlation or relationship between the two {{ form }}. When a request is made to article_detail.html, the comment creation form is displayed in markdown format. And when the modal for editing comments is opened, the comment to be edited is displayed and the comment can be edited.

In reality, however, as shown in the image, the form for creating comments is not displayed in markdown format. And the modal form for editing comments does not display the comment to be edited. Also, pressing the “save change” button does not redirect to the redirect destination.I can’t figure out why this is happening, even though the form instances passed from the view to the template are independent of each other.

The second thing is the difference between POST and GET.
In my understanding, GET is a request method that sends parameters necessary to display a screen. And POST is a request method where the user enters information on the screen and submits it.

In my understanding, <form method="GET"> is to get and display comment edit form in modal window.<form method="POST"> is to submit the updated comment and save it to model. In this situation, it seems to me that both POST and GET are necessary request methods.Therefore I have no idea whether it is appropriate to set the value of the <form method=''> to POST or GET

It probably shouldn’t - if the CommentUpdateView is being rendered and displayed in a modal.

Keep in mind that when a page is rendered and returned to the browser, the view that created that page no longer exists - it is not part of any further processing.

Also stay focused on the fact that templates are not “active” components in Django - they’re just text that is used to create html. The work is done in the views and the rendering engine. You want to avoid having the mindset that “templates do X”. Templates don’t “do” anything.

So the template you render in “View X”, and the variables you use when rendering “View X” are totally separate and independent of any variables used by “View Y” - regardless of the templates being rendered.

These are also separate and distinct issues - we’ll get to that shortly. But I want to skip by these for the moment to address your last question.

Your understanding is correct.

In your Article view, you would use GET to GET the Comment form.

In your Comment form, you would use POST to POST the updated data from that form.

Two different uses for the two different functions needing to be performed.

(Again, focus on what is happening “where” and “when”)

Now going back to the skipped topics:

I’m not familiar with the libraries you’re using to create what you’re referring to the “Markdown format” form field, but I’m guessing it needs to use a custom widget to do that. Whatever it is that’s not working, is not working because you’re not creating the form correctly. Whether it’s because you don’t have the right field defined or you’re not using the right widget, I can’t say. But it’s the definition of that form that you want to look more closely at.

Finally, the redirect issue is going to be more difficult for you to handle. Modals aren’t typically intended to change the underlying page.

You’ll have to look at whatever library you’re using to manage the modals to see if there’s an event you can capture to identify when a modal has been submitted and take appropriate action there. (Perhaps refresh the current page?)

1 Like

Thank you for all the information you have given me.
I’ve learned a lot thanks to you.

After reviewing the library django-mdeditor specifications and editing the HTML, the following points were improved
・Comments can now be entered in a modal form.
・After editing a comment, pressing the “save changes” button redirects the user to the redirection specified in CommentUpdateView.

Thus, I found that this problem is not with the widget or field in django-mdeditor library, but with the instance of CommentCreateForm not rendering as expected.(as previously shown in the image)

To rearrange the current situation, ArticleDetailView specifies article_detail.html as template_name and an instance of CommentCreateForm as context data. The CommentCreateForm instance prepared here is a form for creating comments.

class ArticleDetailView(generic.DetailView):
    model = Article
    template_name = 'article_detail.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        #comment create form
        context['form'] = CommentCreateForm()      

        return context

In CommentUpdateView, since comments are edited in a modal window, article_detail.html is again specified for template_name. The CommentCreateForm instance for editing comments is specified in form_class.

class CommentUpdateView(LoginRequiredMixin, generic.UpdateView):
    model = Comment
    form_class = CommentCreateForm
    template_name = 'article_detail.html'

    def get_success_url(self):
        article = Article.objects.get(comment__pk=self.kwargs['pk'])
        return reverse_lazy('article:article_detail', kwargs={'pk': article.pk})

    def form_valid(self, form):
        messages.success(self.request, 'Your comment has been successfully updated.')
        return super().form_valid(form)

    def form_invalid(self, form):
        messages.error(self.request, 'Failed to correct comment.')
        return super().form_invalid(form)

The article_detail.html contains a modal trigger, a modal window displaying a form for editing comments, and a form for creating comments

{% if comment_list %}
    <section class="comment-list">
      <h2 id="comments" class="comment-title"><i class="fa-regular fa-comments"></i> comment</h2>
      {% for comment in comment_list %}
      <div class="commets-list">
        <li class="comment even thread-even depth-1 parent" id="comment-18730" style="list-style:none">
          <div id="div-comment-18730" class="comment-body article">
            

            {% if user ==  comment.writer %}
            <ul class="navbar-nav">
              <li class="nav-item dropdown">
                <a class="nav-link" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <img class="rounded-circle u-box-shadow-sm mr-2" width="25" height="25" src="{% static 'img/three_dots_icon.png' %}" alt="Icon">
                </a>
                <!-- Modal Trigger-->
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                  <a class="dropdown-item" id="showModal" data-toggle="modal" data-target="#commentModal-{{ comment.pk }}">Edit</a>                                   
                  <a class="dropdown-item" id="showModal2" data-toggle="modal" data-target="#deleteModal-{{ comment.pk }}">Delete</a>
                </div>

                <!-- Comment Edit Modal Form  -->
                <div class="modal fade bd-example-modal-lg" id="commentModal-{{ comment.pk }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                  <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">Edit Your Comment</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <form class="text-center w-md-75 mx-auto" method="POST" enctype="multipart/form-data" action="{% url 'article:comment_update' comment.pk %}">
                        <div class="modal-body">  
                          {% csrf_token %}
                          {{ form.non_field_errors }}
                          {{ form.media }}

                          {% for field in form %}                        
                          <div class="col-xl-12 form-group mb-4">    
                            {{ field|markdown|safe }}
                            {{ field.errors }}
                          </div>
                          {% endfor %}
                          <p>{{ comment.content|markdown|safe }}</p>
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-lg btn-primary py-3 px-4" data-dismiss="modal">Cancel</button>
                          <button type="submit" class="btn btn-lg btn-primary py-3 px-4">Save changes</button>
                        </div>
                      </form>
                    </div>
                  </div>
                </div>
              </li>
            </ul>
            {% endif %}

          <div class="comment-content">
            <p>{{ comment.content|markdown|safe }}</p>
          </div>
          <div class="reply">
            <a class="comment-reply-link" href="#"><span class="fa fa-comment-o"></span> Reply</a>
          </div>
         </div>
        </li>
      </div>
      {% endfor %}
    </section>
    {% endif %}
    
    <!-- Comment Create Form -->
    {% if user.is_authenticated %}
    <h2 class="h1" style="justify-content: center; margin-top: 6rem;">Comment</h2>
    <form method="POST" action="{% url 'article:comment_create' article.pk %}">
      {% csrf_token %}
      {{ form.non_field_errors }}
      
      {% for field in form %}
      <div class="row" style="justify-content: center;">
        <div class="col-xl-12 form-group mb-4">
          {{ form.media }}
          {{ field|markdown|safe }}
          {{ field.errors }}
        </div>
      </div>
      {% endfor %}
      <div class="text-center">
        <button class="btn btn-lg btn-primary py-3 px-4" type="submit" style="margin-bottom: 2rem;">Comment</button>
      </div>  
    </form>
    {% endif %}

Now, consider the following three issues
・The markdown format is applied to the modal form for comment editing.
・The form for creating comments does not apply markdown formatting, and the HTML default input form is displayed.
・The modal form for editing comments does not display the comments to be edited.

I thought CommentUpdateView was rendered when the modal screen was displayed. However, I thought that the ArticleDetailView was actually rendered, not the CommentUpdateView.

Because the comment edit modal form is described prior to the comment create form in article_detail.html, I thought that’s why the comment edit modal form is applied to Mark-down format and the comment create form is not applied to Mark-down format.

So I thought what I should do is to write a process in JavaScript(or something) so that CommentUpdateView is rendered when the modal window is displayed.