def new_lunch_template(request,curr_date): if request.method == 'POST': form = LunchForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/lunch/') else: new_lunch = Lunch() new_lunch.date = curr_date new_lunch.time = "13:00" form = LunchForm(instance=new_lunch) return render_to_response('new_lunch.html', {'form': form})
def curr_week_lunch_list(): weekday_num = datetime.date.today().isoweekday() begin_curr_week_date = datetime.date.today()-datetime.timedelta(days=weekday_num-1) lunch_list = [] for i in range(14): curr_date = begin_curr_week_date + datetime.timedelta(days=i) lunch_suggestions = Lunch.objects.filter(date__exact=curr_date) if not lunch_suggestions: new_lunch = Lunch() new_lunch.date = curr_date new_lunch.time = datetime.time(13,00) # lunch at 13:00 lunch_list.append(new_lunch) else: lunch_list.append(lunch_suggestions[0]) return lunch_list