My Model:
class PartyMaster(models.Model):
party_name = models.CharField(max_length=200,null=True, blank=True)
email = models.EmailField(null=True, blank=True)
contact = models.CharField(max_length=100,null=True, blank=True)
address = models.CharField(max_length=350,null=True, blank=True)
country = models.CharField(max_length=30,null=True, blank=True)
sub_country = models.ForeignKey(CountryCategory,max_length=200,on_delete=models.CASCADE,null=True,blank=True,related_name='party_sub_country')
state = models.CharField(max_length=50,null=True, blank=True)
city = models.CharField(max_length=50,null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.party_name + " "+ self.email
My View: In My Model there are 50 000+ rows
def party_list(request):
parties = PartyMaster.objects.all()
context = {
'parties':parties,
}
return render(request,'party_master/party_edit.html',context)
My Template:
{% extends 'base.html' %}
{% block title %} Party List's {% endblock %}
{% block body %}
<div class="container">
<a href="{% url 'add_party' %}" class="btn btn-primary button_class mt-5">Party Master Form</a>
<div class="py-3">
<div class="table-responsive">
<table class="table table-striped table-hover text-center table-responsive-sm" id="party_table">
<thead class="table-head">
<tr>
<th scope="col">Party Name</th>
<th scope="col">Email</th>
<th scope="col">Contact</th>
<th scope="col">Country</th>
<th scope="col">Sub Country</th>
</tr>
</thead>
<tbody>
{% for party in parties %}
<tr>
<td class="pt-3">{{party.party_name}}</td>
<td class="pt-3">{{party.email}}</td>
<td class="pt-3">{{party.contact}}</td>
<td class="pt-3">{{party.country}}</td>
<td class="pt-3">{{party.sub_country.country_category}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<!-- Datatable -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>
<script>
$(document).ready(function() {
$('#party_table').DataTable( {
dom: 'Bfrtip',
"pageLength": 50,
buttons: [
{
extend: 'excelHtml5',
exportOptions: {
columns: [ 0, 1, 2, 3, 4 ]
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [ 0, 1, 2, 3, 4 ]
}
},
]
} );
} );
</script>
{% endblock %}
how can i load data through server side processing? I am confused how to implement using help in docs. Please provide full implememtation from scratch.
Is there any alternative can also suggest?