0

i have a table showing data from the database but i need it to show the most recent first

Table if u see the picture there is in "monto" a 0.03 thats shown like the last one but it is the most recent in the database, i need the table to show the most recent activity first

Views.py

def index(request):
    monto = Transacciones.objects.filter(owner = request.user)
    paginator = Paginator(monto , 7)

    page_number = request.GET.get('pagina')
    page_obj= Paginator.get_page(paginator,page_number)

    context = {
        'page_obj': page_obj , 
        
    }

    return render(request, 'Admin/Index.cshtml',context)

table html

<div class="">
            <div class="">
                <table class="table h1color bgcolorwhite">
                    <thead>
                        <tr>
                            <th>FECHA</th>
                            <th>MONTO</th>
                            <th>TIPO</th>
                            <th>MONTO COMPRADO BTC</th>
                            <th>MONTO RETIRADO CLP</th>
                            <th>ESTADO</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for a in page_obj %}
                        <tr>
                            <td style="">{{a.date}}</td>
                            <td style="font-weight:bold;">{{a.amount}}</td>
                            <td style="text-align:left">{{a.tipo_transaccion}}</td>
                            <td style="font-weight:bold;">{{a.monto_comprado_btc}}</td>
                            <td style="font-weight:bold;">{{a.monto_retirado_clp}}</td>
                            <td style="">{{a.status}}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>

srry if my english was bad... Thanks a lot!!

Brian Destura
  • 11,487
  • 3
  • 18
  • 34
yRipper
  • 31
  • 3
  • Try with `monto = Transacciones.objects.filter(owner = request.user).order_by('-fetcha')` – Brian Destura Jul 21 '21 at 04:09
  • You can override this on a per-QuerySet basis by using the order_by method. Like Transacciones.objects.filter(owner = request.user).order_by('-fetcha').The result will be ordered by fetcha in descending manner. – Ashish Nautiyal Jul 21 '21 at 04:16
  • Thanks!! it worked perfectly, had to change DateField to DateTimeField on models for it to be more precise – yRipper Jul 21 '21 at 05:10

1 Answers1

0

If views.py file fetch the data like the following to get the activities in order "recent to last":

monto = Transacciones.objects.filter(owner = request.user)[::-1]
Rohit_VE
  • 109
  • 5