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 6889055
In Process

The Archive Base Latest Questions

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

I have a problem in subtracting a two values. i just want to be

  • 0

I have a problem in subtracting a two values. i just want to be like this
a = b – c

here is my code in my handlers.py

 def create(self, request): 
        if not self.has_model():
            return rc.NOT_IMPLEMENTED

        attrs = self.flatten_dict(request.POST)

        if attrs.has_key('data'):
            ext_posted_data = SimplerXMLGenerator(request.POST.get('data'))
            attrs = self.flatten_dict(ext_posted_data)

        prod = Product.objects.get(id=attrs['id'])
        prod_quantity = prod.quantity

        quantity_order = attrs['quantity']

        sumOfQuantity = Booking.objects.filter(date_select=attrs['date_select']).aggregate(Sum('quantity')

        prodAvailable = prod_quantity - sumOfQuantity

        if prodAvailable = 0:
            #select another date
            return rc.NOT_HERE
        if prodAvailable <= quantity_order:
            return prodAvailable
        else :
            total = float(quantity_order) * prod.price
            inst = self.model(
                date_select = attrs['date_select'],
                product_name = prod.name,
                quantity = attrs['quantity'],
                price = prod.price,
                totalcost = total,
                first_name = attrs['first_name'],
                last_name = attrs['last_name'],
                contact = attrs['contact'],
                product = prod
                           )
            inst.save()
            return inst

The problem is in prodAvailable = prod_quantity - sumOfQuantity
my question is how can i declare it correctly?

thanks in advance :p

here is my trace back …

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  89.                     response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
  67.             if (not _is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in _is_valid_path
  154.         urlresolvers.resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  342.     return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, &quot;urlpatterns&quot;, self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/agileone/workspace/bookproj/../bookproj/api/urls.py" in &lt;module&gt;
  3. from api.handlers import *

Exception Type: SyntaxError at /api/bookings
Exception Value: invalid syntax (handlers.py, line 94)

furthermore, when i trying to do it in my python shell… it goes like this:

>>> sumOfQuantity = Booking.objects.filter(date_select='2011-11-29').aggregate(Sum('quantity'))
>>> print sumOfQuantity
{'quantity__sum': 2}
>>> prod_quantity = 1
>>> prodAvailable = prod_quantity - sumOfQuantity
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'int' and 'dict'
  • 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-27T06:06:28+00:00Added an answer on May 27, 2026 at 6:06 am

    If you really want it to look like a = b - c then you’ll have to change your assignment to sumOfQuantity:

    sumOfQuantity = Booking.objects.filter(date_select='2011-11-29').aggregate(Sum('quantity'))['quantity__sum']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have an algorithm where I create two bi-dimensional arrays like this: TYPE TPtrMatrixLine
I have problem with return statment >.< I want to store all magazine names
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem with fancybox. I want to write a function that will run
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have a strange problem which probably has a very simple solution, I just
I have two tables (subjects and pages) in one-to-many relations. I want to add
I have a problem in adding or subtracting 2 days to the target day...
I'm wondering what the best way to approach this problem is... I have an

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.