# 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 admin
from .models import Cart, CartItem


class CartItemInline(admin.TabularInline):
    model = CartItem
    
    
class CartAdmin(admin.ModelAdmin):
    inlines = [CartItemInline]

    class Meta:
        model = Cart
        

# 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/admin.py
from django.contrib import admin
from .models import Cart, CartItem



class CartItemInline(admin.TabularInline):
    model = CartItem
    
    
class CartAdmin(admin.ModelAdmin):
    inlines = [CartItemInline]

    class Meta:
        model = Cart
        

admin.site.register(Cart, CartAdmin)