0

I have "Post" and "Slide" classes in models.py:

class Slide(models.model):
post = models.ForeignKey(Post, related_name="slides")
name = models.TextField()

"Slide is inlined in "Post" in admin.py, I am using bootstrap for frontend. I want to display all "slides" for only that post when I click on a button but when it goes to modal it's only taking first post.id in modal, my template looks something like this:`

    {% if posts %}
        {% for post in posts %}
         <button type="button" class="btn btn-default" data-toggle="modal" data-target="#sample-1"> Slides </button>

             <div id="sample-1" class="modal fade">
                 <div class="modal-body">
                    {% for slide in slides %}

                    {{slide.body}}

                    {% endfor %}
                </div>
          </div>
    {% endfor %}
{% endif %}

<script type="text/javascript">
    $('#sample-1').modalSteps();
</script>
jayasth
  • 163
  • 1
  • 2
  • 6

1 Answers1

0

The problem is that you have the same id for all items ... "sample-1"

https://softwareengineering.stackexchange.com/questions/127178/two-html-elements-with-same-id-attribute-how-bad-is-it-really

JQuery to check for duplicate ids in a DOM

Community
  • 1
  • 1
madzohan
  • 11,488
  • 9
  • 40
  • 67