ソースを参照

Moved models into subapps

master
David Winterbottom 15年前
コミット
f7e6eb17bb
5個のファイルの変更77行の追加5行の削除
  1. 0
    0
      TODO
  2. 0
    3
      oscar/models.py
  3. 18
    0
      oscar/product/admin.py
  4. 58
    2
      oscar/product/models.py
  5. 1
    0
      settings.py

+ 0
- 0
TODO ファイルの表示


+ 0
- 3
oscar/models.py ファイルの表示

@@ -1,3 +0,0 @@
1
-from django.db import models
2
-
3
-# Create your models here.

+ 18
- 0
oscar/product/admin.py ファイルの表示

@@ -0,0 +1,18 @@
1
+from product.models import AttributeType
2
+from product.models import Type
3
+from product.models import Item
4
+from product.models import Attribute
5
+from django.contrib import admin
6
+
7
+class AttributeInline(admin.TabularInline):
8
+    model = Attribute
9
+
10
+class ItemAdmin(admin.ModelAdmin):
11
+    list_display = ('name', 'partner_id', 'date_available', 'date_created', 'is_valid')
12
+    inlines = [AttributeInline]
13
+
14
+
15
+admin.site.register(AttributeType)
16
+admin.site.register(Type)
17
+admin.site.register(Item, ItemAdmin)
18
+admin.site.register(Attribute)

+ 58
- 2
oscar/product/models.py ファイルの表示

@@ -1,4 +1,60 @@
1 1
 from django.db import models
2 2
 
3
-    
4
-    
3
+class AttributeType(models.Model):
4
+    """Defines a product atrribute type"""
5
+    name = models.CharField(max_length = 128)
6
+
7
+    def __unicode__(self):
8
+        return self.name
9
+
10
+
11
+class Type(models.Model):
12
+    """Defines a product type"""
13
+    name = models.CharField(max_length = 128)
14
+    attribute_types = models.ManyToManyField('product.AttributeType')
15
+
16
+    def __unicode__(self):
17
+        return self.name
18
+
19
+class Item(models.Model):
20
+    """The base product object"""
21
+    name = models.CharField(max_length = 128)
22
+    partner_id = models.CharField(max_length = 32)
23
+    type = models.ForeignKey('product.Type')
24
+    date_available = models.DateField()
25
+    date_created = models.DateTimeField()
26
+
27
+    def __unicode__(self):
28
+        return self.name
29
+
30
+    def is_valid(self):
31
+        """
32
+        Returns true if the product is valid.
33
+
34
+        Validity is based on whether the product has all required attribute types
35
+        configured for the product_class it is in.
36
+
37
+        Returns:
38
+            A boolean if the product is valid
39
+        """
40
+        required_attribute_names = []
41
+        for attribute_type in self.type.attribute_types.all():
42
+            required_attribute_names.append(attribute_type.name)
43
+
44
+        for attribute in self.attribute_set.all():
45
+            required_attribute_names.remove(attribute.attribute_type.name)
46
+
47
+        return 0 == len(required_attribute_names)
48
+
49
+class Attribute(models.Model):
50
+    """An individual product attribute"""
51
+    attribute_type = models.ForeignKey('product.AttributeType')
52
+    product = models.ForeignKey('product.Item')
53
+    value = models.CharField(max_length = 256)
54
+
55
+
56
+class StockRecord(models.Model):
57
+    """A stock keeping record"""
58
+    product = models.ForeignKey('product.Item')
59
+    price_excl_tax = models.FloatField()
60
+    tax = models.FloatField()

+ 1
- 0
settings.py ファイルの表示

@@ -94,6 +94,7 @@ INSTALLED_APPS = (
94 94
     'south',
95 95
     'oscar.payment',
96 96
     'oscar.order',
97
+    'oscar.product',
97 98
 )
98 99
 
99 100
 # Local overrides

読み込み中…
キャンセル
保存