Django и javascript вопрос показывать и скрывать форму редактирования из списка выбранных запросов
В моем индексе есть следующее
<div id="posts">
{% for post in posts %}
<div class="card">
<div class="card-body">
<h5 class="card-title"><a href="{% url 'profile' post.user.username %}">{{post.user.username}}</a> wrote:</h5>
{%if post.user_id == user.id %}
<div class="cardn">
<a href="#" data-id="{{post.id}}" onclick="editPost('{{post.id}}')">Edit</a>
<div class="{{post.id}}" data-id="{{post.id}}" id="{{post.id}}" style="display: none">
<form action="editpost/{{post.id}} " method="post">
{% csrf_token %}
<div class="form-group">
<label for="post_text" class="h4">Edit Post</label><br>
<textarea name="post_text">{{post.text}}</textarea> </div>
<button type="submit" class="btn btn-primary btn-sm">Edit</button>
</form>
</div>
</div>
{%endif%}
<p class="card-text" id="post_text_{{post.id}}"> {{ post.text }}</p>
<p class="card-text"><small class="text-muted">on: {{post.post_date}}</small></p>
<p class="card-text">
<div data-id="{{post.id}}"
class="card-link {% if post.current_like > 0 %} fas {%else%} far {% endif %} fa-heart"> <small
class="text-muted">{{post.like_set.count}}</small>
</div>
</p>
</div>
</div>
{% empty %}
<h2>No posts</h2>
{% endfor %}
Что я хотел бы достичь, так это показать только форму редактирования для нажатой кнопки редактирования, используя javascript
вот мое мнение
def editpost(request, id):
post = Post.objects.get(
id=id)
if request.method == "POST":
text = request.POST.get("post_text")
Post.objects.filter(
id=id, user_id=request.session['_auth_user_id']).update(text=text)
return HttpResponseRedirect(reverse("index"))
else:
return render(request, "network/editpost.html", {
'post': post
})
мой JS, который не работает document.addEventListener("click", editPost);
function editPost(id){ // Listener sees triggering event
var id = this.getAttribute("data-id");
document.querySelector("#" + id).style.display = "block";
}
спасибо заранее