0

**I have a Django code where i am retrieving the tin number and tin type **

if ("_generate_form_1099" in self.request.POST) and self.request.POST["_generate_form_1099"] == "Generate Form 1099":
        elif ("_send-bulk-email" in self.request.POST) and self.request.POST["_self-bulk-email"] == "Send Bulk Email":
        elif ("action" in self.request.POST) and self.request.POST["action"] == "Save Tin":
            user_id = self.request.POST.get('user_id')
            tin = self.request.POST.get('tin_value')
            tin_type = self.request.POST.get('tin_type')
            input_name = f"tin_value_{{ user.id }}"
            if input_name in self.request.POST:
                tin_value = self.request.POST[input_name]
                user = CustomUser.objects.get(id=user_id)
                user.seller_tin = tin
                user.tin_type = tin_type
                user.save()
            context = {'user_contexts': user_contexts}
            return render(self.request, 'admin/generate_form.html', context)
        elif ("_send-tin-email" in self.request.POST) and self.request.POST["_send-tin-email"] == "Send Email":
            user_id = self.request.POST.get('user_id')
            user_name = self.request.POST.get('user_name')
            email_mess = {"seller": user_name}
            send_notification([user_id], 'notification_31', email_mess)

 `


```
`{% extends "admin/base_site.html" %}

{% block content %}

<form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.as_p }}
    <div>
        <input type="submit" class="action-button" value="Generate Form 1099" name="_generate_form_1099">
    </div><br>
    {% if download_link %}
        <a href="{{ download_link }}" target="_blank" class="download-button">
            <div style="display:inline-block">Download</div>
        </a>
    {% elif download_link %}
        <div><p>The Form 1099 has not been generated for the specified fiscal year. Click on Generate Form 1099</p></div>
    {% endif %}

{{ block.super }}

</form>
<div>
    <h2>Seller Information Without Tin</h2>
    <table>
        <tr>
            <th class="header-table">USER ID</th>
            <th class="header-table">Name</th>
            <th class="header-table">Email</th>
            <th class="header-table">TIN Details</th>
            <th class="header-table">Actions</th>
        </tr>
        {% for user in user_contexts %}
        <tr>
            <td>{{ user.id }}</td>
            <td>{{ user.name }}</td>
            <td>{{ user.email }}</td>
            <td>
                <form method="get" enctype="multipart/form-data">
                        {% csrf_token %}
                <input type="hidden" name="user_id" value="{{ user.id }}">
                <input type="text" name="tin_value_{{ user.id }}" id="tin_value_{{ user.id }}" value="" placeholder="Add Tin Number">
                <input type="text" name="tin_type_{{ user.id }}" id="tin_type_{{ user.id }}" value="" placeholder="Add Tin type">
                <input class="action-button save-button" type="submit" value="Save Tin" name="action">
                </form>
            </td>
            <td>
                <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                <input type="hidden" name="user_id" value="{{ user.id }}">
                <input type="hidden" name="user_name" value="{{ user.name }}">
                <input class="action-button send-email-button" type="submit" value="Send Email" name="_send-tin-email">
                 </form>
            </td>
        </tr>
        {% endfor %}
    </table>
    <div class="bulk-arangement">
        <input class="action-button" type="submit" value="Send Bulk Email" name="_send-bulk-email">
    </div>
</div>

{% endblock %}
         

The value that is coming from like user_id and user_name should be the correct user and the save button was only working for first but it should use for all 
toyota Supra
  • 3,181
  • 4
  • 15
  • 19

0 Answers0