0

I am trying to solve an issue with getting all dates within a range into my Django application template. I have a start date and an end date of a time sheet which are defined and I am able to pass them into the template. However, I want to fill in all of the dates in between into an HTML table but cannot seem to find a solution to this problem, as most solutions are for 1 date only. Any and all help is greatly appreciated!

views.py

def time_page(request, result_name):
    records = TimeSheetMain.objects.get(timeSheet_code=result_name)
    empID = Employee.objects.get()
    req_user = request.user
    recordsUser = records.user
    if req_user == recordsUser:
        return render_to_response('ts.html',
                                  {'records': records, 'empID': empID},
                                  context_instance=RequestContext(request))

HTML Call:

Date Range: {{ records.startDate }} - {{ records.endDate }}

urls.py

url(r'^ts/(.{36})', 'TimeSheetApp.views.time_page', name="time_page"),
Shang Wang
  • 24,909
  • 20
  • 73
  • 94
majestic1
  • 1
  • 1
  • I may not have it right, but you want to find all dates between two dates? http://stackoverflow.com/a/1060330/1753891 – duffn Aug 13 '15 at 00:59

1 Answers1

0
  1. In View: collect all dates into a list, see https://stackoverflow.com/a/1060330/1753891

  2. In template: Use template forloop to populate the HTML table.

    {% for d in date_list %}
    {# table cell here #}
    {% endfor %}
    
Community
  • 1
  • 1
haiiiiiyun
  • 19
  • 3