def reservation_create(request, restaurant_id): restaurant = Restaurant.objects.get(pk=restaurant_id) form = ReservationForm(request.POST) reservation = form.instance reservation.restaurant = restaurant reservation.user = request.user if form.is_valid(): form.save() return redirect(reverse('restaurant_show', args=[restaurant.pk])) else: context = { 'restaurant': restaurant, 'reservation_form': form, 'title': restaurant.name } return render(request, 'restaurant_details.html', context)
def restaurant_show(request, id): restaurant = Restaurant.objects.get(pk=id) context = {'restaurant': restaurant, 'title': restaurant.name} if request.user.is_authenticated: context['reservations'] = restaurant.reservations.filter( user=request.user) context['reservation_form'] = ReservationForm() return render(request, 'restaurant_details.html', context)
def restaurant_show(request, id): restaurant = Restaurant.objects.get(pk=id) context = {'restaurant': restaurant, 'title': restaurant.name} if request.user.is_authenticated: context['reservations'] = restaurant.reservations.filter( user=request.user) context['reservation_form'] = ReservationForm() if request.user == restaurant.owner: start_date = datetime.today() end_date = start_date - timedelta(weeks=26) vip_count = restaurant.reservations.filter(date__range=(start_date, end_date)) vip_count = vip_count return render(request, 'restaurant_details.html', context)