Null value or empty value saved with each refresh, even click button submit duplicate value, please find the following models and views file. please look at envlope button in the image that is submit button which create another model db called Emails.
fdisplay.html
{% for i in obj %}
<tr>
{% if i.id %}
<th scope="row">{{forloop.counter0|add:obj.start_index}}</th>
<td>{{i.institution}}</td>
<td>{{i.fullname}}</td>
<td>{{i.email}}</td>
<td>{{i.contact}}</td>
<td>{{i.position}}</td>
<td><img src={{i.uploaddata.url}} class="img-fluid img-thumbnail" alt={{i.fullname}} style="width:100px; height: 60px"></td>
<td>
<a href="{% url 'update' i.id %}" class="btn btn-warning btn-sm"><i class="fa-regular fa-pen-to-square"></i></a>
<form action="{% url 'delete' i.id %}" method="POST" class="d-inline">
{% csrf_token %}
<button type="submit" class="btn btn-danger btn-sm">
<i class="fa-regular fa-trash-can"></i>
</button>
</form>
<!-- sent data -->
<form method="POST" class="d-inline">
{% csrf_token %}
<div class="d-none">
<input type="text" name="email" id="email" class="form-control w-50 form-row" value="{{i.useremail}}" required>
<input type="text" name="password" id="password" class="form-control w-50 form-row mt-1" value="{{i.userpassword}}" required>
</div>
<button type="submit" class="btn btn-danger btn-sm">
<i class="fa-solid fa-envelope-circle-check"></i>
</button>
</form>
</td>
</tr>
{% endif %}
{% endfor %}
models.py
class EmailDb(models.Model):
institution = models.CharField(max_length=300, blank=True, null=True)
fullname = models.CharField(max_length=50, blank=True, null=True)
contact = models.IntegerField()
email = models.CharField(max_length=300, blank=True, null=True)
position = models.CharField(max_length=100, blank=True, null=True)
uploaddata = models.FileField(upload_to='appointment_letter')
useremail = models.CharField(max_length=100, blank=True, null=True)
userpassword = models.CharField(max_length=100, blank=True, null=True)
def __str__(self):
return self.fullname
class EmailS(models.Model):
ename = models.CharField(max_length=100, blank=True, null=True)
epassword = models.CharField(max_length=200, blank=True, null=True)
def __str__(self):
return self.ename
views.py
def EAdmin(request):
obj = EmailDb.objects.all().order_by('id')
# paginator
paginator = Paginator(obj, 4)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
print(page_obj.start_index)
total_page = page_obj.paginator.num_pages
#
emaild = EmailDb.objects.all()
# POST Request
email = request.POST.get('email', '')
password = request.POST.get('password', '')
data = EmailS(ename=email, epassword=password)
data.save()
#amrit
context = {'obj': page_obj, 'lastpage': total_page, 'totalPagelist': [n+1 for n in range(total_page)], 'em': emaild, 'email':email, 'password': password}
return render(request, 'NEC/fdisplay.html', context)