Browse Source

Merged in 3 more commits of Jon's updating products

master
David Winterbottom 15 years ago
parent
commit
2b73c88c40
2 changed files with 21 additions and 4 deletions
  1. 2
    0
      oscar/product/admin.py
  2. 19
    4
      oscar/product/models.py

+ 2
- 0
oscar/product/admin.py View File

2
 from product.models import Type
2
 from product.models import Type
3
 from product.models import Item
3
 from product.models import Item
4
 from product.models import Attribute
4
 from product.models import Attribute
5
+from product.models import AttributeTypeMembership
5
 from django.contrib import admin
6
 from django.contrib import admin
6
 
7
 
7
 class AttributeInline(admin.TabularInline):
8
 class AttributeInline(admin.TabularInline):
13
 
14
 
14
 
15
 
15
 admin.site.register(AttributeType)
16
 admin.site.register(AttributeType)
17
+admin.site.register(AttributeTypeMembership)
16
 admin.site.register(Type)
18
 admin.site.register(Type)
17
 admin.site.register(Item, ItemAdmin)
19
 admin.site.register(Item, ItemAdmin)
18
 admin.site.register(Attribute)
20
 admin.site.register(Attribute)

+ 19
- 4
oscar/product/models.py View File

1
 from django.db import models
1
 from django.db import models
2
 
2
 
3
 class AttributeType(models.Model):
3
 class AttributeType(models.Model):
4
-    """Defines a product atrribute type"""
4
+    """Defines a product attribute type"""
5
     name = models.CharField(max_length = 128)
5
     name = models.CharField(max_length = 128)
6
 
6
 
7
     def __unicode__(self):
7
     def __unicode__(self):
11
 class Type(models.Model):
11
 class Type(models.Model):
12
     """Defines a product type"""
12
     """Defines a product type"""
13
     name = models.CharField(max_length = 128)
13
     name = models.CharField(max_length = 128)
14
-    attribute_types = models.ManyToManyField('product.AttributeType')
14
+    attribute_types = models.ManyToManyField('product.AttributeType', through = 'product.AttributeTypeMembership')
15
 
15
 
16
     def __unicode__(self):
16
     def __unicode__(self):
17
         return self.name
17
         return self.name
18
 
18
 
19
+class AttributeTypeMembership(models.Model):
20
+    RELATIONSHIP_CHOICES = (
21
+        ('optional', 'optional'),
22
+        ('required', 'required'),
23
+        ('required_basket', 'required for purchase'),
24
+    )
25
+    type = models.ForeignKey('product.Type')
26
+    attribute_type = models.ForeignKey('product.AttributeType')
27
+    relation_type = models.CharField(max_length = 16, choices = RELATIONSHIP_CHOICES, default = 'optional')
28
+    
29
+    def __unicode__(self):
30
+        return "%s -> %s (%s)" % (self.type.name, self.attribute_type.name, self.relation_type)
31
+    
32
+
19
 class Item(models.Model):
33
 class Item(models.Model):
20
     """The base product object"""
34
     """The base product object"""
21
     name = models.CharField(max_length = 128)
35
     name = models.CharField(max_length = 128)
38
             A boolean if the product is valid
52
             A boolean if the product is valid
39
         """
53
         """
40
         required_attribute_names = []
54
         required_attribute_names = []
41
-        for attribute_type in self.type.attribute_types.all():
55
+        for attribute_type in self.type.attribute_types.filter(attributetypemembership__relation_type = 'required'):
42
             required_attribute_names.append(attribute_type.name)
56
             required_attribute_names.append(attribute_type.name)
43
 
57
 
44
         for attribute in self.attribute_set.all():
58
         for attribute in self.attribute_set.all():
45
-            required_attribute_names.remove(attribute.attribute_type.name)
59
+            if attribute.attribute_type.name in required_attribute_names:
60
+                required_attribute_names.remove(attribute.attribute_type.name)
46
 
61
 
47
         return 0 == len(required_attribute_names)
62
         return 0 == len(required_attribute_names)
48
 
63
 

Loading…
Cancel
Save