how to assign value in django

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

 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 =,
                quantity = attrs['quantity'],
                price = prod.price,
                totalcost = total,
                first_name = attrs['first_name'],
                last_name = attrs['last_name'],
                contact = attrs['contact'],
                product = prod
            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 ...

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/" in get_response
  89.                     response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/" in process_request
  67.             if (not _is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/middleware/" in _is_valid_path
  154.         urlresolvers.resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/" in resolve
  342.     return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/" in resolve
  252.                     sub_match = pattern.resolve(new_path)
File "/usr/local/lib/python2.7/dist-packages/django/core/" in resolve
  250.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/" 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/" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/" in import_module
  35.     __import__(name)
File "/home/agileone/workspace/bookproj/../bookproj/api/" in &lt;module&gt;
  3. from api.handlers import *

Exception Type: SyntaxError at /api/bookings
Exception Value: invalid syntax (, 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'


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']

Need Your Help

php function execute - connection between php and C++ serverbased

php c++

I am currently working on a project, where I have to build a webpage, where I get some Data from the User and than convert that to a tree.

What could justify the complexity of Plone?

python content-management-system plone zope

Plone is very complex. Zope2, Zope3, Five, ZCML, ZODB, ZEO, a whole bunch of acronyms and abbreviations.