Added a view for "top 5 sandwiches", currently using "all sandwiches" template.
[~kgodey/maayanwich.git] / views.py
index 23f9269..3b12aec 100644 (file)
--- a/views.py
+++ b/views.py
@@ -40,4 +40,14 @@ def all_sandwich(request):
                sandwiches = Sandwich.objects.all()
        except Sandwich.DoesNotExist:
                raise Http404
+       return render_to_response('allsandwiches.html', {'sandwiches': sandwiches,})
+       
+def newsandwiches(request):
+       try:
+               if Sandwich.objects.count() > 5:
+                       sandwiches = Sandwich.objects.order_by('date_made')[:5]
+               else:
+                       sandwiches = Sandwich.objects.order_by('date_made')
+       except Sandwich.DoesNotExist:
+               raise Http404
        return render_to_response('allsandwiches.html', {'sandwiches': sandwiches,})
\ No newline at end of file