def reservation(request, reservation_id): instance = get_object_or_404(Reservation, id=reservation_id) form = NewResForm(request.POST or None, instance=instance) if form.is_valid(): form.save() return HttpResponseRedirect('/hotel/rooms/') return direct_to_template(request, 'hotel/NewRes.html', {'form': form})
def newres(request): if request.method == 'POST': form = NewResForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/hotel/rooms/') else: form = NewResForm(initial={'created': timezone.now() }) return render(request, 'hotel/NewRes.html', {'form': form})
def newres_room(request, room_id): try: p = Room.objects.get(number=room_id) except Room.DoesNotExist: raise Http404 if request.method == 'POST': form = NewResForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/hotel/rooms/') else: form = NewResForm(initial={'created': timezone.now() }) return render(request, 'hotel/NewRes.html', {'form': form,'room': p,})