ahh, okay. Letās try another approach to see if you can nail down that error. Iām not sure why itās not working.
Ā
def reserve(request, park_id):
Ā Ā Ā
Ā Ā Ā # Get the User
Ā Ā Ā # This is different than the method youāre using
Ā Ā Ā # but I think it may be what you want.
Ā
Ā Ā Ā user = self.request.user
Ā
Ā Ā Ā # Grab that Notification and Park
Ā Ā Ā # In your method, you were throwing a 404 error. Iām
Ā Ā Ā # not sure if thatās what youāre actually after (page not found)
Ā Ā Ā # or if youād rather give a server error because the user attempted
Ā Ā Ā # to use a notification or park that didnāt exist.
Ā
Ā Ā Ā # Also, Iām a bit confused by the variable names, haha. Iād think the Park
Ā Ā Ā # object would take the park_id and the Notification object would use
Ā Ā Ā # something else.
Ā
Ā Ā Ā notification = Notification.objects.get(pk = park_id)
Ā Ā Ā park = Park.objects.get(pk = 1)
Ā
Ā Ā Ā # This will check to see if that POST Variable is available.
Ā Ā Ā ifĀ ātimeoutā is in request.POST:
Ā
Ā Ā Ā Ā Ā Ā Ā # Grab the Timeout Variable
Ā Ā Ā Ā Ā Ā Ā timeout = int(request.POST[ātimeoutā])
Ā
Ā Ā Ā Ā Ā Ā Ā # Letās build the Reservation object piece by piece to see what the problem is.
Ā Ā Ā Ā Ā Ā Ā reservation = Reservation.objects.create()
Ā Ā Ā Ā Ā Ā Ā reservation.user = user
Ā Ā Ā Ā Ā Ā Ā # ....
Ā Ā Ā Ā Ā Ā Ā reservation.notification = notification
Ā Ā Ā Ā Ā Ā Ā reservation.timeout = timeout
Ā Ā Ā Ā Ā Ā Ā # ...
Ā Ā Ā Ā Ā Ā Ā reservation.save()
Ā
Ā Ā Ā Ā Ā Ā Ā return HttpResponse(...)
Ā
Ā Ā Ā # This is the error case where the timeout wasnāt POST'ed.
Ā Ā Ā else:
Ā Ā Ā Ā Ā Ā Ā raise Exception(āThe timeout variable wasnāt posted.ā)
Ā
This time, you should see exactly where that error is popping up. Also, ModelForm + CreateView would be a great an easy combination for this exact situation.
Ā Ā Ā Ā Ā Ā Ā
Good luck!
-Kurtis Mullins