Kaynağa Gözat

Added first version of a dropapp command

master
David Winterbottom 15 yıl önce
ebeveyn
işleme
89a3ecbdf3

+ 0
- 0
oscar/management/__init__.py Dosyayı Görüntüle


+ 0
- 0
oscar/management/commands/__init__.py Dosyayı Görüntüle


+ 12
- 0
oscar/management/commands/dropapp.py Dosyayı Görüntüle

@@ -0,0 +1,12 @@
1
+from django.core.management.base import BaseCommand, CommandError
2
+from django.core.management.commands.sqlclear import Command as SqlClearCommand
3
+
4
+class Command(BaseCommand):
5
+    args = '<app_name app_name ...>'
6
+    help = 'Drops the db tables for the given apps'
7
+
8
+    def handle(self, *args, **kwargs):
9
+        com = SqlClearCommand()
10
+        self.stdout.write("SET FOREIGN_KEY_CHECKS=0;\n")
11
+        for app_name in args:
12
+            self.stdout.write(com.handle(app_name))

+ 8
- 0
oscar/offer/models.py Dosyayı Görüntüle

@@ -2,6 +2,7 @@ from django.contrib.auth.models import User
2 2
 from django.db import models
3 3
 from django.utils.translation import ugettext as _
4 4
 
5
+
5 6
 class ConditionalOffer(models.Model):
6 7
     name = models.CharField(max_length=128)
7 8
     description = models.TextField(blank=True)
@@ -13,6 +14,7 @@ class ConditionalOffer(models.Model):
13 14
     priority = models.IntegerField()
14 15
     created_date = models.DateTimeField(auto_now_add=True)
15 16
 
17
+
16 18
 class Condition(models.Model):
17 19
     COUNT, VALUE = ("Count", "Value")
18 20
     TYPE_CHOICES = (
@@ -23,6 +25,7 @@ class Condition(models.Model):
23 25
     type = models.CharField(max_length=128, choices=TYPE_CHOICES)
24 26
     value = models.FloatField()
25 27
 
28
+
26 29
 class Benefit(models.Model):
27 30
     PERCENTAGE, FIXED = ("Percentage", "Absolute")
28 31
     TYPE_CHOICES = (
@@ -33,8 +36,13 @@ class Benefit(models.Model):
33 36
     type = models.CharField(max_length=128, choices=TYPE_CHOICES)
34 37
     value = models.FloatField()
35 38
 
39
+
36 40
 class Range(models.Model):
37 41
     name = models.CharField(max_length=128)
42
+    includes_all_products = models.BooleanField(default=False)
43
+    included_products = models.ManyToManyField('product.Item', related_name='includes')
44
+    excluded_products = models.ManyToManyField('product.Item', related_name='excludes')
45
+
38 46
 
39 47
 class Voucher(models.Model):
40 48
     """

+ 22
- 20
oscar/product/models.py Dosyayı Görüntüle

@@ -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()

+ 1
- 0
settings.py Dosyayı Görüntüle

@@ -92,6 +92,7 @@ INSTALLED_APPS = (
92 92
     'django.contrib.admin',
93 93
     'django_extensions',
94 94
     'south',
95
+    'oscar',
95 96
     'oscar.payment',
96 97
     'oscar.order',
97 98
     'oscar.product',

Loading…
İptal
Kaydet