Skip to content

Commit

Permalink
Reordered methods and Meta classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Glass committed Feb 14, 2011
1 parent e2b3c13 commit f354d3e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
11 changes: 6 additions & 5 deletions shop/models/cartmodel.py
Expand Up @@ -21,6 +21,9 @@ class Cart(models.Model):
date_created = models.DateTimeField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)

class Meta:
app_label = 'shop'

def __init__(self, *args, **kwargs):
super(Cart, self).__init__(*args,**kwargs)
self.update() # This populates transient fields when coming from the DB
Expand Down Expand Up @@ -73,8 +76,6 @@ def update(self):
for value in self.extra_price_fields.itervalues():
self.total_price = self.total_price + value

class Meta:
app_label = 'shop'

class CartItem(models.Model):
'''
Expand All @@ -93,6 +94,9 @@ class CartItem(models.Model):

product = models.ForeignKey(Product)

class Meta:
app_label = 'shop'

def update(self):
self.line_subtotal = self.product.get_price() * self.quantity
self.line_total = self.line_subtotal
Expand All @@ -105,6 +109,3 @@ def update(self):
self.line_total = self.line_total + value

return self.line_total

class Meta:
app_label = 'shop'
6 changes: 4 additions & 2 deletions shop/models/clientmodel.py
Expand Up @@ -11,6 +11,9 @@ class Client(models.Model):
date_of_birth = models.DateField(null=True, blank=True)
created = models.DateTimeField(auto_now_add=True)

class Meta:
app_label = 'shop'

def __unicode__(self):
return "ClientProfile for %s %s" % (self.user.first_name, self.user.last_name)

Expand All @@ -22,8 +25,7 @@ def shipping_address(self):
def billing_address(self):
return Address.objects.filter(client=self).filter(is_billing=True)[0]

class Meta:
app_label = 'shop'


class Country(models.Model):
name = models.CharField(max_length=255)
Expand Down
12 changes: 6 additions & 6 deletions shop/models/ordermodel.py
Expand Up @@ -133,6 +133,9 @@ class Order(models.Model):

objects = OrderManager()

class Meta:
app_label = 'shop'

def is_payed(self):
'''Has this order been integrally payed for?'''
return self.amount_payed == self.order_total
Expand All @@ -147,9 +150,6 @@ def shipping_costs(self):
for cost in cost_list:
sum = sum + cost.value
return sum

class Meta:
app_label = 'shop'

class OrderItem(models.Model):
'''
Expand All @@ -166,13 +166,13 @@ class OrderItem(models.Model):
line_subtotal = CurrencyField()
line_total = CurrencyField()

class Meta:
app_label = 'shop'

@property
def product(self):
return Product.objects.get(pk=self.product_reference)

class Meta:
app_label = 'shop'

class OrderExtraInfo(models.Model):
'''
A holder for extra textual information to attach to this order.
Expand Down
26 changes: 13 additions & 13 deletions shop/models/productmodel.py
Expand Up @@ -15,18 +15,18 @@ class Category(models.Model):
parent_category = models.ForeignKey('self', related_name="children",
null=True, blank=True)

class Meta:
verbose_name_plural = "categories"
app_label = 'shop'

def __unicode__(self):
return self.name

def get_products(self):
'''
Gets the products belonging to this category (not recursively)
'''
return Product.objects.filter(category=self)

def __unicode__(self):
return self.name

class Meta:
verbose_name_plural = "categories"
app_label = 'shop'

class ProductManager(models.Manager):

Expand Down Expand Up @@ -57,16 +57,19 @@ class Product(models.Model):

objects = ProductManager()

class Meta:
app_label = 'shop'

def __unicode__(self):
return self.name

def save(self, *args, **kwargs):
'''
Saves the name of the subtype to the subtype column.
'''
self.subtype = self.__class__.__name__.lower()
super(Product, self).save(*args, **kwargs)

def __unicode__(self):
return self.name

def specify(self):
'''
This magic method returns this as an instance of the most specific
Expand All @@ -80,6 +83,3 @@ def get_price(self):
'''
return self.unit_price

class Meta:
app_label = 'shop'

0 comments on commit f354d3e

Please sign in to comment.