-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
54 lines (39 loc) · 1.59 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from django.db import models
# Create your models here.
class Addon(models.Model):
name = models.CharField(max_length = 100)
price = models.DecimalField(max_digits = 5, decimal_places = 2)
def _unicode_(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length = 50)
base_price = models.DecimalField(max_digits = 7, decimal_places = 2)
short_description = models.CharField(max_length = 100)
long_description = models.CharField(max_length = 1000)
thumbnail = models.ImageField(upload_to = 'thumbnails')
product_image = models.ImageField(upload_to = 'images')
addons = models.ManyToManyField(Addon)
def _unicode_(self):
return self.name
class User(models.Model):
email_id = models.EmailField(max_length = 75)
def _unicode_(self):
return self.email_id
class Item(models.Model):
delivery_address = models.CharField(max_length = 1000)
price = models.DecimalField(max_digits = 7, decimal_places = 2)
user = models.OneToOneField(User)
product = models.OneToOneField(Product)
def _unicode_(self):
return self.product.name
class CartManager:
def add_to_cart(request, product_id, quantity):
product = Product.objects.get(id=product_id)
cart = Cart(request)
cart.add(product, product.unit_price, quantity)
def remove_from_cart(request, product_id):
product = Product.objects.get(id=product_id)
cart = Cart(request)
cart.remove(product)
def get_cart(request):
return render_to_response('cart.html', dict(cart=Cart(request)))