title: Record Clicks on Modal Toggle
body: <p>I have a page that catalogues media (think similar to an instagram page). The media is viewable on modals, and I'd like to record a &quot;view count&quot; for each piece of media. So whenever the modal containing that media is toggled open, it records a view.</p>
  <p>This is a simplified version of my code:</p>
  <pre><code>&lt;button data-toggle=&quot;modal&quot; data-target=&quot;media-number-999&quot;&gt;Click to view Media 999!&lt;/button&gt;
  &lt;div class=&quot;modal&quot; id=&quot;media-number-999&quot;&gt;Media #999 viewable here!&lt;/div&gt;
  </code></pre>
  <p>I also have a page set up where visiting that page automatically increases the viewcount by 1, and then redirects elsewhere (using django)</p>
  <pre><code>urls.py:
  path('views/&lt;id&gt;/', views.media_views, name=&quot;mediaviews&quot;),
  
  views.py:
  def media_views(request,id):
      Media.objects.filter(id=id).update(views=F('views') + 1)
      return redirect('media_detail', id=id)
  </code></pre>
  <p>The reason I'm doing this is so that I can then reference the viewcount in the database to use for sorting/filtering/etc.</p>
  <p>How can I make a button that both opens the modal, and also records a visit to /views/999/ ? Also open to alternative approaches if there are better ways! I've tried to figure out how to use Ajax to do this but haven't had any luck.</p>
  <p>Thanks!</p>