# Path: src/cart/models.py
# class Cart(models.Model):
#     user = models.ForeignKey(User, null=True, blank=True)
#     total = models.DecimalField(max_digits=50, default=0, decimal_places=2)
#     active = models.BooleanField(default=True)
#     timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
#     updated = models.DateTimeField(auto_now_add=False, auto_now=True)
#     
#     def __unicode__(self):
#         return str(self.id)
#     
#     '''
#     def save(self, *args, **kwargs):
#         #override the save function
#         totals = [item.product.price for item in self.cartitem_set.all()]
#         new_total = sum(totals)
#         self.total = new_total
#         super(Cart, self).save(*args, **kwargs)
#         
#         totals = []
#         for item in self.cartitem_set.all():
#             totals.append(item.product.price)
#         '''
# 
# class CartItem(models.Model):
#     cart = models.ForeignKey(Cart) #create cart model
#     product = models.ForeignKey(Product)
#     timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
#     updated = models.DateTimeField(auto_now_add=False, auto_now=True)
#     
#     def __unicode__(self):
#         return "%s" %(self.product.title)


from django.contrib import messages
from django.shortcuts import render_to_response, Http404, RequestContext, HttpResponseRedirect
from django.core.urlresolvers import reverse
from products.models import Product
from products.views import check_product #takes user and product as args
from .models import Cart, CartItem
        cart_id = request.session['cart_id']
    except:
        cart_id = False
        
    if cart_id:
        cart = Cart.objects.get(id=cart_id)
    else:
        cart = False
        
    items = CartItem.objects.filter(cart=cart)
    if len(items) > 0:
        exists = True
    else:
        exists = False
    
    return render_to_response('cart/view_cart.html', locals(), context_instance=RequestContext(request))
        
        
def update_cart(request, id):
    try:
        product = Product.objects.get(id=id)
    except:
        product = False
    
    try:
        cart_id = request.session['cart_id']
    except:
        cart_id = False
    try:
        cart = Cart.objects.get(id=cart_id)

# Path: src/cart/models.py
# class Cart(models.Model):
#     user = models.ForeignKey(User, null=True, blank=True)
#     total = models.DecimalField(max_digits=50, default=0, decimal_places=2)
#     active = models.BooleanField(default=True)
#     timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
#     updated = models.DateTimeField(auto_now_add=False, auto_now=True)
#     
#     def __unicode__(self):
#         return str(self.id)
#     
#     '''
#     def save(self, *args, **kwargs):
#         #override the save function
#         totals = [item.product.price for item in self.cartitem_set.all()]
#         new_total = sum(totals)
#         self.total = new_total
#         super(Cart, self).save(*args, **kwargs)
#         
#         totals = []
#         for item in self.cartitem_set.all():
#             totals.append(item.product.price)
#         '''
# 
# class CartItem(models.Model):
#     cart = models.ForeignKey(Cart) #create cart model
#     product = models.ForeignKey(Product)
#     timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
#     updated = models.DateTimeField(auto_now_add=False, auto_now=True)
#     
#     def __unicode__(self):
#         return "%s" %(self.product.title)


# Path: src/cart/views.py
from django.contrib import messages
from django.shortcuts import render_to_response, Http404, RequestContext, HttpResponseRedirect
from django.core.urlresolvers import reverse
from products.models import Product
from products.views import check_product #takes user and product as args
from .models import Cart, CartItem

        cart_id = request.session['cart_id']
    except:
        cart_id = False
        
    if cart_id:
        cart = Cart.objects.get(id=cart_id)
    else:
        cart = False
        
    items = CartItem.objects.filter(cart=cart)
    if len(items) > 0:
        exists = True
    else:
        exists = False
    
    return render_to_response('cart/view_cart.html', locals(), context_instance=RequestContext(request))
        
        
def update_cart(request, id):
    try:
        product = Product.objects.get(id=id)
    except:
        product = False
    
    try:
        cart_id = request.session['cart_id']
    except:
        cart_id = False
    try:
        cart = Cart.objects.get(id=cart_id)

    except Cart.DoesNotExist: