the django paginator data I use in my project does not work properly in sorting, for example, although I have records dated 2021 in my records, when I sort by date, it only sorts records dated 2020, here is my codes:
images;
after sorting;
about 2021 dated records finding by filtering;
views.py;
gmembers_list = gunluk.objects.all()
paginator = Paginator(gmembers_list, 1000000000000000)
page = request.GET.get('page')
try:
gmembers = paginator.page(page)
except PageNotAnInteger:
gmembers = paginator.page(1)
except EmptyPage:
gmembers = paginator.page(paginator.num_pages)
return render(request, 'gunlukistakibi.html', {'gmembers': gmembers})a
html for listing;
<div class="card mb-3">
<div class="card-header">
<i class="fas fa-table"></i>
Günlük İş Takibi
<a class="btn btn-sm btn-success" href="{% url 'gcreate' %}" style="padding: 8px; float: right; background-color: green; color: white;">EKLE</a>
</div>
<div class="card-body">
<div class="table-responsive ">
<table class="table table-striped table-bordered text-center dataTable no-footer align-center align-middle " id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Tarih</th>
<th>Ad Soyad</th>
<th>Vardiya</th>
<th> Açıklama </th>
<th>İncident</th>
<th>Alınan</br>Aksiyon</th>
<th>Ulaşılamayan</br>Ekip</th>
<th>Ulaşılamayan</br>Bilgisi</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for gmember in gmembers %}
<tr>
<td>{{gmember.tarih|date:"d-m-Y"}}</td>
<td>{%if gmember.adsoyad2 == null%} {{ gmember.adsoyad}} {%else%} {{ gmember.adsoyad}} - {{ gmember.adsoyad2}} {%endif%}</td>
<td>{{ gmember.vardiya }}</td>
<td>{{ gmember.aciklama }}</td>
<td>{{ gmember.incident }}</td>
<td>{{ gmember.alinanaksiyon }}</td>
<td>{{ gmember.ulasilmayanekip }}</td>
<td>{{ gmember.ulasilmayanbilgisi }}</td>
<td>
<a class="btn btn-sm btn-warning" href="gedit/{{ gmember.id }}"> <span class="fa fa-edit"></span> </a>
<a class="btn btn-sm btn-danger" href="gdelete/{{ gmember.id }}"><span class="fa fa-trash"></span> </a>
</td>
</tr>
I don't see any sorting by date in your code. Can you try with gmembers_list = gunluk.objects.all().order_by("-date")
(or whatever your date field on this model is named)?
By default, if you don't provide an ordering on the Model.Meta
class, and no ordering when building your queryset, the sorting can be unstable depending on your database.