I am creating my custom admin panel in Django, i don't want to use django default admin panel, But i want sorting filters in dajngo, If a user click on email
then email should be in ascending
order, and if the user click again on email then the emails
will be in descending order, Please let me know how i can do it.
Here is my models.py
file...
class Model1(models.Model):
email= models.Charfield(blank=True)
phone= models.Charfield(blank=True)
here is my views.py
file...
def display_data(request):
test_display=UserFilter(request.GET,
queryset=Model1.objects.select_related('customer__user))
paginator = Paginator(test_display.qs, 10)
page_number = request.GET.get('page')
testdisplay = paginator.get_page(page_number)
return render(request, 'page.html', {'test_display':test_display, 'testdisplay':testdisplay})
here is my page.html
file
<th><a href="javascript:void()">Email (CLick on this field)</a></th>
{% for i in testdisplay %}
<tr>
<td>
{{i.email}}
</td>
</tr>
{% endfor %}
here is my filters.py
file code...
calss UserFilter(django_filters.FilterSet):
class Meta:
models= Model1
fields ['type','status']