[Answered ]-How to increment database row by 1 for every time a link is clicked?

1👍

you need some identifier to fetch that particular row from db, right now you are updating all the rows with this logic:

    if request.method == 'POST':
        T_shirt.objects.update(views=F('views') + 1)

for the current implementation, since you are using forms, you can add a hidden element inside the forms like:

<form method="POST" type="submit">
<button style="border: none;">
    {% csrf_token %}
 <input type="hidden" name="tshirt_id" value="{{ v.id }}" />
    <a href="{{ v.Link }}" rel="noopener noreferrer">
  <img src="{{ v.Images }}" width="150" height="150">
    </a>
        </button>
   </form>

then change your view to get tshirt_id from request and update that row

if request.method == 'POST':
        T_shirt.objects.filter(id=request.POST.get('tshirt_id')).update(views=F('views') + 1)

Leave a comment