Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
django order csv using os.listdir

I'm a beginner in django, I'm trying to sort my csv by date In my view. I can export my schedules in csv and display them in my view but I don’t know how to sort them by date by the most recent one. But in My view not in my directory.

In my template it's Like this :

  • export_21_11_2021-151707.csv
  • export_22_11_2021-151707.csv
  • export_23_11_2021-151707.csv

But I want to sort by date the most recent like this :

  • export_23_11_2021-151707.csv
  • export_22_11_2021-151707.csv
  • export_21_11_2021-151707.csv

and where I show all export :

    def vm_schedule_download(request):
    media_url = settings.MEDIA_ROOT
    if not os.path.exists(f'{media_url}appli'):
        os.makedirs(f'{media_url}appli')
    if not os.path.exists(f'{media_url}appli/vm'):
        os.makedirs(f'{media_url}appli/vm')
    if not os.path.exists(f'{media_url}'
                          f'appli/vm/schedule_export'):
        os.makedirs(f'{media_url}appli/vm/schedule_export')
    filenames = os.listdir(f'{media_url}appli/vm/schedule_export')
    return render(request, 'appli/vm/vm_schedule_download.html',
                  {'filenames': filenames})

I tried sorted() but does nothink.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I found a solution using os.path.getmtime. There was already a solution in this topic stackoverflow.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!