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