Parcourir la source

Added some sample shops where the models are customised and a new

product image app
master
David Winterbottom il y a 15 ans
Parent
révision
fcaa0bc2b7

+ 4
- 1
TODO Voir le fichier

@@ -1,4 +1,7 @@
1 1
 Fields to write:
2 2
 - Postcode field
3 3
 - Currency field
4
-- Country field for addresses
4
+- Country field for addresses
5
+
6
+Sample shop:
7
+- How to have the admin site reflect your local models

sampleapp/__init__.py → oscar/image/__init__.py Voir le fichier


+ 27
- 0
oscar/image/abstract_models.py Voir le fichier

@@ -0,0 +1,27 @@
1
+"""
2
+Abstract models for the product images app
3
+"""
4
+
5
+from django.db import models
6
+from django.utils.translation import ugettext as _
7
+
8
+
9
+class AbstractImage(models.Model):
10
+    """
11
+    An image of a product  
12
+    """
13
+    product = models.ForeignKey('product.Item', related_name='images')
14
+    path = models.ImageField(upload_to='product-images/%Y/%m/')
15
+    # Use display_order to determine which is the "primary" image
16
+    display_order = models.PositiveIntegerField()
17
+    date_created = models.DateTimeField(auto_now_add=True)
18
+    
19
+    def is_primary(self):
20
+        return self.display_order == 0
21
+    
22
+    class Meta:
23
+        abstract = True
24
+
25
+    def __unicode__(self):
26
+        return "Image of '%s'" % self.product
27
+

+ 4
- 0
oscar/image/admin.py Voir le fichier

@@ -0,0 +1,4 @@
1
+from django.contrib import admin
2
+from oscar.image.models import *
3
+
4
+admin.site.register(Image)

+ 5
- 0
oscar/image/models.py Voir le fichier

@@ -0,0 +1,5 @@
1
+from oscar.image.abstract_models import AbstractImage
2
+
3
+class Image(AbstractImage):
4
+    pass
5
+

+ 23
- 0
oscar/image/tests.py Voir le fichier

@@ -0,0 +1,23 @@
1
+"""
2
+This file demonstrates two different styles of tests (one doctest and one
3
+unittest). These will both pass when you run "manage.py test".
4
+
5
+Replace these with more appropriate tests for your application.
6
+"""
7
+
8
+from django.test import TestCase
9
+
10
+class SimpleTest(TestCase):
11
+    def test_basic_addition(self):
12
+        """
13
+        Tests that 1 + 1 always equals 2.
14
+        """
15
+        self.failUnlessEqual(1 + 1, 2)
16
+
17
+__test__ = {"doctest": """
18
+Another way to test that 1 + 1 is equal to 2.
19
+
20
+>>> 1 + 1 == 2
21
+True
22
+"""}
23
+

+ 1
- 0
oscar/image/views.py Voir le fichier

@@ -0,0 +1 @@
1
+# Create your views here.

+ 2
- 2
oscar/product/abstract_models.py Voir le fichier

@@ -1,7 +1,7 @@
1 1
 from django.db import models
2 2
 from django.utils.translation import ugettext_lazy as _
3 3
 
4
-class AbstractItemType(models.Model):
4
+class AbstractItemClass(models.Model):
5 5
     """
6 6
     Defines an item type (equivqlent to Taoshop's MediaType).
7 7
     """
@@ -29,7 +29,7 @@ class AbstractItem(models.Model):
29 29
     parent = models.ForeignKey('self', blank=True, null=True)
30 30
     title = models.CharField(_('name'), max_length=255)
31 31
     description = models.TextField(_('description'), blank=True, null=True)
32
-    item_type = models.ForeignKey('product.ItemType', verbose_name=_('item type'))
32
+    item_class = models.ForeignKey('product.ItemClass', verbose_name=_('item type'))
33 33
     attribute_types = models.ManyToManyField('product.AttributeType', through='ItemAttributeValue')
34 34
     date_created = models.DateTimeField(auto_now_add=True)
35 35
     date_updated = models.DateTimeField(auto_now=True)

+ 1
- 1
oscar/product/models.py Voir le fichier

@@ -9,7 +9,7 @@ class ItemType(AbstractItemType):
9 9
 class Item(AbstractItem):
10 10
     pass
11 11
 
12
-class AttributeType(AbstractAttributeType):
12
+class AttributeClass(AbstractAttributeType):
13 13
     pass
14 14
 
15 15
 class ItemAttributeValue(AbstractItemAttributeValue):

+ 0
- 5
sampleapp/payment/admin.py Voir le fichier

@@ -1,5 +0,0 @@
1
-from django.contrib import admin
2
-from sampleapp.payment.models import *
3
-
4
-admin.site.register(Source)
5
-admin.site.register(Transaction)

+ 0
- 8
sampleapp/payment/models.py Voir le fichier

@@ -1,8 +0,0 @@
1
-from django.db import models
2
-from oscar.payment.abstract_models import AbstractSource, AbstractTransaction
3
-
4
-class Source(AbstractSource):
5
-    num_transactions = models.IntegerField(default=0)
6
-
7
-class Transaction(AbstractTransaction):
8
-    pass

sampleapp/payment/__init__.py → sampleshop_books/__init__.py Voir le fichier


+ 0
- 0
sampleshop_books/product/__init__.py Voir le fichier


+ 23
- 0
sampleshop_books/product/models.py Voir le fichier

@@ -0,0 +1,23 @@
1
+"""
2
+Bookshop product models
3
+"""
4
+from django.db import models
5
+from oscar.product.abstract_models import *
6
+
7
+class ItemType(AbstractItemType):
8
+    pass
9
+
10
+class Item(AbstractItem):
11
+    format = models.CharField(max_length=128, default="Paperback")
12
+    isbn = models.CharField(max_length=13)
13
+    contributors = models.ManyToManyField('product.Contributor')
14
+    date_published = models.DateTimeField()
15
+
16
+class Contributor(models.Model):
17
+    name = models.CharField(max_length=255)
18
+
19
+class AttributeType(AbstractAttributeType):
20
+    pass
21
+
22
+class ItemAttributeValue(AbstractItemAttributeValue):
23
+    pass

+ 0
- 0
sampleshop_clothing/__init__.py Voir le fichier


+ 0
- 0
sampleshop_clothing/product/__init__.py Voir le fichier


+ 16
- 0
sampleshop_clothing/product/models.py Voir le fichier

@@ -0,0 +1,16 @@
1
+"""
2
+Clothes shop product models
3
+"""
4
+from oscar.product.abstract_models import *
5
+
6
+class ItemType(AbstractItemType):
7
+    pass
8
+
9
+class Item(AbstractItem):
10
+    label = models.CharField(max_length=32, default='Gucci') 
11
+
12
+class AttributeType(AbstractAttributeType):
13
+    pass
14
+
15
+class ItemAttributeValue(AbstractItemAttributeValue):
16
+    pass

+ 6
- 3
settings.py Voir le fichier

@@ -27,7 +27,7 @@ DATABASES = {
27 27
 # timezone as the operating system.
28 28
 # If running in a Windows environment this must be set to the same as your
29 29
 # system time zone.
30
-TIME_ZONE = 'America/Chicago'
30
+TIME_ZONE = 'Europe/London'
31 31
 
32 32
 # Language code for this installation. All choices can be found here:
33 33
 # http://www.i18nguy.com/unicode/language-identifiers.html
@@ -92,17 +92,20 @@ INSTALLED_APPS = (
92 92
     'django.contrib.admin',
93 93
     'django_extensions',
94 94
     'south',
95
+    'test_extensions',
96
+    # Apps from oscar
95 97
     'oscar',
96 98
     'oscar.order',
97
-    'oscar.product',
99
+    #'oscar.product',
98 100
     'oscar.basket',
99 101
     'oscar.payment',
100 102
     'oscar.offer',
101 103
     'oscar.address',
102 104
     'oscar.stock',
105
+    'oscar.image',
103 106
     # To use an alternative app to one of oscar's core ones,
104 107
     # add it here (eg replace oscar.payment with sampleapp.payment)
105
-    'test_extensions',
108
+    'sampleshop_clothing.product'
106 109
 )
107 110
 
108 111
 # Local overrides

+ 1
- 2
urls.py Voir le fichier

@@ -1,7 +1,6 @@
1 1
 from django.conf.urls.defaults import *
2
-
3
-# Uncomment the next two lines to enable the admin:
4 2
 from django.contrib import admin
3
+
5 4
 admin.autodiscover()
6 5
 
7 6
 urlpatterns = patterns('',

Chargement…
Annuler
Enregistrer