Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6902467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:48:06+00:00 2026-05-27T07:48:06+00:00

I am developing a reservation system, and i have a function that save the

  • 0

I am developing a reservation system, and i have a function that save the quantity of a product… My question is why I got this problem ? when i

`curl -l -X POST -d "product=3&client=1&function=insert_booking&check_in=2011-12-15&check_out=2011-12-10&no_of_adult=2&no_of_kid=1&quantity=2&first_name=asda&last_name=sdsd&contact=34343" http://127.0.0.1:8000/api/reserve`


Piston/0.3dev (Django 1.3.1) crash report:

Traceback (most recent call last):

  File "/home/agileone/workspace/bookproj/api/handlers.py", line 206, in create
    prodAvailable = Hotel.objects.get_hotel_sum_quantity(attrs['product'], attrs['check_in'], attrs['check_out'])

  File "/home/agileone/workspace/bookproj/../bookproj/booking/models.py", line 49, in get_hotel_sum_quantity
    if prod_Available <= 0:

UnboundLocalError: local variable 'prod_Available' referenced before assignment

but when i test in the python shell, it works fine :

>>> from booking.models import *
>>> Hotel.objects.get_hotel_sum_quantity(3, '2011-12-10', '2011-12-15')1

here is my code in models.py

def get_hotel_sum_quantity(self, product_id, checkin_date, checkout_date):
        check_in = datetime.datetime.strptime(checkin_date, '%Y-%m-%d')
        check_in = check_in.date()
        start_date = check_in.day

        check_out = datetime.datetime.strptime(checkout_date, '%Y-%m-%d')
        check_out = check_out.date()
        end_date = check_out.day

        prod = Product.objects.get(id=product_id)

        for x in range(start_date,end_date + 1):
            x = x - start_date
            delta = datetime.timedelta(days=x)
            all_date = check_in + delta
            sumOfQuantity = HotelCheck.objects.filter(date_booked=all_date, product=prod).aggregate(Sum('quantity'))['quantity__sum']
            if sumOfQuantity == None:
                sumOfQuantity = 0
            prod_Available = prod.quantity - sumOfQuantity
            #global prod_Available
        if prod_Available <= 0:
            status = 0
        else:
            status = 1

        return status

and my handlers.py

if attrs['function'] == 'insert_booking':

                prodAvailable = Hotel.objects.get_hotel_sum_quantity(attrs['product'], attrs['check_in'], attrs['check_out'])
                if float(prodAvailable) <= 0:
                    disp = Hotel.objects.get_hotel_show_available(attrs['product'], attrs['check_in'], attrs['check_out'])
                    return {'status': '0', 'message': 'not OK!'}, disp    

can anyone can explain my situation and give some idea on how to solve it…?
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:48:07+00:00Added an answer on May 27, 2026 at 7:48 am

    Sometimes you loop is not entered, so prod_Available is not created, but you try to reference it.

    Before the loop put prod_Available = 0:

        prod = Product.objects.get(id=product_id)
    
        prod_Available = 0 # !
    
        for x in range(start_date,end_date + 1):
            x = x - start_date
            delta = datetime.timedelta(days=x)
            all_date = check_in + delta
            sumOfQuantity = HotelCheck.objects.filter(date_booked=all_date, product=prod).aggregate(Sum('quantity'))['quantity__sum']
            if sumOfQuantity == None:
                sumOfQuantity = 0
            prod_Available = prod.quantity - sumOfQuantity
            #global prod_Available
        if prod_Available <= 0:
            status = 0
        else:
            status = 1
    
        return status
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web application that provide a service of online reservation, and I
Developing for iPhone, I have a collection of points that I need to make
Developing iphone application using makkit framework. I have got the map view integrated in
I'm developing a Hotel reservation iPhone application . I tab view that I mention
I am developing a rails app. (I don't think this is a rails-specific problem)
Developing ios app. I have an object class Product.h and .m respectively along with
i have an Issue i am developing a reservation management Issue when user Complete
Developing a web application that I've registered with Twitter. In this app, I might
Developing a little survey webapp, ran into problem that deals with ranges for rating
Developing Java, you have always learned that its best to create an ArrayList by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.