|
@@ -2,7 +2,7 @@ from django.db import models
|
2
|
2
|
|
3
|
3
|
class AttributeType(models.Model):
|
4
|
4
|
"""Defines a product attribute type"""
|
5
|
|
- name = models.CharField(max_length = 128)
|
|
5
|
+ name=models.CharField(max_length=128)
|
6
|
6
|
|
7
|
7
|
def __unicode__(self):
|
8
|
8
|
return self.name
|
|
@@ -10,22 +10,24 @@ class AttributeType(models.Model):
|
10
|
10
|
|
11
|
11
|
class Type(models.Model):
|
12
|
12
|
"""Defines a product type"""
|
13
|
|
- name = models.CharField(max_length = 128)
|
14
|
|
- attribute_types = models.ManyToManyField('product.AttributeType', through = 'product.AttributeTypeMembership')
|
|
13
|
+ name=models.CharField(max_length=128)
|
|
14
|
+ attribute_types=models.ManyToManyField('product.AttributeType', through='product.AttributeTypeMembership')
|
15
|
15
|
|
16
|
16
|
def __unicode__(self):
|
17
|
17
|
return self.name
|
18
|
18
|
|
19
|
19
|
|
20
|
20
|
class AttributeTypeMembership(models.Model):
|
21
|
|
- RELATIONSHIP_CHOICES = (
|
|
21
|
+ RELATIONSHIP_CHOICES=(
|
22
|
22
|
('optional', 'optional'),
|
23
|
23
|
('required', 'required'),
|
24
|
24
|
('required_basket', 'required for purchase'),
|
25
|
25
|
)
|
26
|
|
- type = models.ForeignKey('product.Type')
|
27
|
|
- attribute_type = models.ForeignKey('product.AttributeType')
|
28
|
|
- relation_type = models.CharField(max_length = 16, choices = RELATIONSHIP_CHOICES, default = 'optional')
|
|
26
|
+ type=models.ForeignKey('product.Type')
|
|
27
|
+ # Some attributes like clothes sizes need to be displayed in a set order (eg: S,M,L,XL)
|
|
28
|
+ display_order=models.IntegerField(default=0)
|
|
29
|
+ attribute_type=models.ForeignKey('product.AttributeType')
|
|
30
|
+ relation_type=models.CharField(max_length=16, choices=RELATIONSHIP_CHOICES, default='optional')
|
29
|
31
|
|
30
|
32
|
def __unicode__(self):
|
31
|
33
|
return "%s -> %s (%s)" % (self.type.name, self.attribute_type.name, self.relation_type)
|
|
@@ -33,11 +35,11 @@ class AttributeTypeMembership(models.Model):
|
33
|
35
|
|
34
|
36
|
class Item(models.Model):
|
35
|
37
|
"""The base product object"""
|
36
|
|
- name = models.CharField(max_length = 128)
|
37
|
|
- partner_id = models.CharField(max_length = 32)
|
38
|
|
- type = models.ForeignKey('product.Type')
|
39
|
|
- date_available = models.DateField()
|
40
|
|
- date_created = models.DateTimeField()
|
|
38
|
+ name=models.CharField(max_length=128)
|
|
39
|
+ partner_id=models.CharField(max_length=32)
|
|
40
|
+ type=models.ForeignKey('product.Type')
|
|
41
|
+ date_available=models.DateField()
|
|
42
|
+ date_created=models.DateTimeField()
|
41
|
43
|
|
42
|
44
|
def __unicode__(self):
|
43
|
45
|
return self.name
|
|
@@ -52,8 +54,8 @@ class Item(models.Model):
|
52
|
54
|
Returns:
|
53
|
55
|
A boolean if the product is valid
|
54
|
56
|
"""
|
55
|
|
- required_attribute_names = []
|
56
|
|
- for attribute_type in self.type.attribute_types.filter(attributetypemembership__relation_type = 'required'):
|
|
57
|
+ required_attribute_names=[]
|
|
58
|
+ for attribute_type in self.type.attribute_types.filter(attributetypemembership__relation_type='required'):
|
57
|
59
|
required_attribute_names.append(attribute_type.name)
|
58
|
60
|
|
59
|
61
|
for attribute in self.attribute_set.all():
|
|
@@ -65,13 +67,13 @@ class Item(models.Model):
|
65
|
67
|
|
66
|
68
|
class Attribute(models.Model):
|
67
|
69
|
"""An individual product attribute"""
|
68
|
|
- attribute_type = models.ForeignKey('product.AttributeType')
|
69
|
|
- product = models.ForeignKey('product.Item')
|
70
|
|
- value = models.CharField(max_length = 256)
|
|
70
|
+ attribute_type=models.ForeignKey('product.AttributeType')
|
|
71
|
+ product=models.ForeignKey('product.Item')
|
|
72
|
+ value=models.CharField(max_length=256)
|
71
|
73
|
|
72
|
74
|
|
73
|
75
|
class StockRecord(models.Model):
|
74
|
76
|
"""A stock keeping record"""
|
75
|
|
- product = models.ForeignKey('product.Item')
|
76
|
|
- price_excl_tax = models.FloatField()
|
77
|
|
- tax = models.FloatField()
|
|
77
|
+ product=models.ForeignKey('product.Item')
|
|
78
|
+ price_excl_tax=models.FloatField()
|
|
79
|
+ tax=models.FloatField()
|