Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 KB | None | 0 0
  1. from django.db import models
  2.  
  3. class Supplier(models.Model):
  4. name = models.CharField('Supplier Name', max_length=200)
  5. address1 = models.CharField('Street', max_length=200)
  6. address2 = models.CharField(blank=True, null=True, max_length=200)
  7. address3 = models.CharField('Town', max_length=200)
  8. address4 = models.CharField('Postcode', max_length=200)
  9. telephone = models.CharField(max_length=200)
  10. email = models.EmailField()
  11. notes = models.TextField(blank=True, null=True, help_text = "Notes about this supplier")
  12. def __unicode__(self): # Python 3: def __str__(self):
  13. return self.name
  14.  
  15. class Product(models.Model):
  16. supplier = models.ManyToManyField(Supplier)
  17. name = models.CharField(max_length=200, help_text="The name of the case. Will form the URL of page. e.g. Mixed Rioja Case")
  18. slug = models.SlugField(max_length=255, unique=True,
  19. help_text='Unique value for product page URL, created automatically from name.')
  20. sku = models.CharField(max_length=50)
  21. is_featured = models.BooleanField(default=False, help_text="To appear on front page? Most recent item first.")
  22. is_active = models.BooleanField(default=True)
  23. is_bestseller = models.BooleanField(default=False, help_text="Click to add to 'bestsellers' list.")
  24. price = models.DecimalField(max_digits=5, decimal_places=2, help_text="pounds.pence")
  25. old_price = models.DecimalField(max_digits=9,decimal_places=2,
  26. blank=True,default=0.00, help_text="If item is on sale, put the old price here, and change price to sale price. Will automatically be added to 'offers' section")
  27. description = models.TextField(help_text="Prose. Promotion. Propaganda")
  28. head_line = models.CharField(max_length=200, help_text="Will be main title in large letters on home page. E.g. Gobsmacking Rioja.")
  29. tag_line = models.CharField(max_length=200, help_text="In italics inder main title. Call to action. E.g. Buy this you really really want it.")
  30. stock = models.IntegerField(max_length=4, help_text="Amount of item you have to sell")
  31. control_stock = models.BooleanField(default=True, help_text="Uncheck if you don't want the stock controlled. i.e. it won't say sold out when stock goes to zero")
  32. created_at = models.DateTimeField(auto_now_add=True)
  33. updated_at = models.DateTimeField(auto_now=True)
  34.  
  35. def __unicode__(self): # Python 3: def __str__(self):
  36. return self.name
  37.  
  38. def price_pence(self):
  39. return int(self.price*100)
  40.  
  41. @property
  42. def sale_price(self):
  43. if self.old_price > self.price:
  44. return self.price
  45. else:
  46. return None
  47.  
  48. @property
  49. def isinstock(self):
  50. if self.control_stock == True:
  51. if self.stock >=1:
  52. return True
  53. else:
  54. return False
  55. else:
  56. return None
  57.  
  58.  
  59. class Images(models.Model):
  60. product = models.ForeignKey(Product)
  61. image = models.FileField(upload_to = 'images/', default = 'images/no-img.png', help_text="Nice images of product for detail page. Size XX x XXpx please. Default image will appear if none supplied.")
  62. image_featured = models.BooleanField(default = False, help_text="Do you want this image to be the image on the home page if the product is a featured product?")
  63. def __unicode__(self):
  64. return self.image
  65.  
  66. class Video(models.Model):
  67. product = models.OneToOneField(Product)
  68. video_url_embed = models.TextField(blank=True, null=True, help_text="The main focus. Get video embed code from share buttons on YouTube or Vimeo")
  69.  
  70. def __unicode__(self):
  71. return self.video_url_embed
  72.  
  73. class Country(models.Model):
  74. name = models.CharField(max_length=200, help_text="Country E.g. Spain")
  75. writeup = models.TextField(blank=True, null=True, help_text="Blurb About the Country")
  76. def __unicode__(self): # Python 3: def __str__(self):
  77. return self.name
  78.  
  79. class Region(models.Model):
  80. country = models.ForeignKey(Country)
  81. name = models.CharField(max_length=200, help_text="Region E.g. Rioja")
  82. writeup = models.TextField(blank=True, null=True, help_text="Blurb About the Region")
  83. def __unicode__(self): # Python 3: def __str__(self):
  84. return self.name
  85.  
  86. class Producer(models.Model):
  87. name = models.CharField(max_length=200, help_text="Producer E.g. La Rioja Alta")
  88. writeup = models.TextField(help_text="Blurb About the Producer")
  89. location_map_url_embed = models.TextField(blank=True, null=True, help_text="Optional. A link to pinpoint where in the world the producer is. Get embed code from google maps or open street map.")
  90. def __unicode__(self): # Python 3: def __str__(self):
  91. return self.name
  92.  
  93. class GrapeVariety(models.Model):
  94. name = models.CharField(max_length=200, help_text="Grape Variety E.g. Tempranillo")
  95. writeup = models.TextField(blank=True, null=True, help_text="Blurb About the Grape Variety")
  96. def __unicode__(self): # Python 3: def __str__(self):
  97. return self.name
  98.  
  99. class Wine(Product):
  100. SIZE_OF_BOTTLE = [
  101. (375,375),
  102. (500,500),
  103. (750,750),
  104. (1500,1500),
  105. (3000,3000),
  106. ]
  107. ORGANIC_BIO = [
  108. ("Conventional","Conventional"),
  109. ("Organic Uncertified","Organic Uncertified"),
  110. ("Organic Certified","Organic Certified"),
  111. ("Biodynamic Uncertified","Biodynamic Uncertified"),
  112. ("Biodynamic Certified","Biodynamic Certified"),
  113. ]
  114.  
  115. WINE_COLOUR = [
  116. ("White","White"),
  117. ("Red","Red"),
  118. ("Rose","Rose"),
  119. ]
  120.  
  121. WINE_STYLE = [
  122. ("Still","Still"),
  123. ("Sparkling","Sparkling"),
  124. ("Fortified","Fortified"),
  125. ("Dessert","Dessert"),
  126. ]
  127.  
  128. style = models.CharField(max_length=15, choices=WINE_STYLE, default = "Still", help_text="Wine Style")
  129. colour = models.CharField(max_length=5, choices=WINE_COLOUR, help_text="Wine Colour")
  130. region = models.ForeignKey(Region)
  131. producer = models.ForeignKey(Producer)
  132. year = models.IntegerField(max_length=4, help_text="YYYY. E.g. 1985")
  133. grapes = models.ManyToManyField(GrapeVariety)
  134. bottle_size = models.IntegerField(max_length=4, choices=SIZE_OF_BOTTLE, default = '750', help_text="Size of bottle in ml")
  135. organicbio = models.CharField(max_length=50, choices=ORGANIC_BIO, default = 'Conventional', help_text="Is this beauty organic/bio/conventional?")
  136. lowyields = models.BooleanField(default=False, help_text="Is this beauty from low-yielding vines?")
  137. lowsulphur = models.BooleanField(default=False, help_text="Is this beauty a low-sulphur wine?")
  138. oldvines = models.BooleanField(default=False, help_text="Is this beauty from old vines?")
  139.  
  140.  
  141. class Case(Product):
  142. BOTTLES_IN_THE_CASE = [
  143. (1,1),
  144. (3,3),
  145. (6,6),
  146. (12,12),
  147. (24,24),
  148. ]
  149. wine = models.ForeignKey(Wine)
  150. bottles_in_case = models.IntegerField(max_length=2, choices=BOTTLES_IN_THE_CASE, default = '6', help_text="Number of bottles in the case")
  151.  
  152.  
  153. class Tasting(Product):
  154. FOOD_AT_TASTING = [
  155. ('Wine Only','Wine Only'),
  156. ('Beer Only','Beer Only'),
  157. ('Nibbles','Nibbles'),
  158. ('Cheese Pairing','Cheese Pairing'),
  159. ('Food Pairing','Food Pairing'),
  160. ('Light Meal','Light Meal'),
  161. ('Full Meal','Full Meal'),
  162. ('Dinner','Dinner'),
  163. ]
  164.  
  165. address_1 = models.CharField(max_length=200, default = 'Wine Store at No. 4', help_text="Address Line One")
  166. address_2 = models.CharField(max_length=200, default = '4 Beulah Road', help_text="Address Line Two")
  167. address_3 = models.CharField(max_length=200, default = 'Rhiwbina', help_text="Address Line Three")
  168. address_4 = models.CharField(max_length=200, default = 'Cardiff', help_text="Address Line Four")
  169. postcode = models.CharField(max_length=200, default = 'CF14 6LX', help_text="Postcode")
  170. telephone = models.CharField(max_length=200, default = '029 2061 1139', help_text="Telephone")
  171. date_of_tasting = models.DateField(help_text="Date of the Tasting")
  172. time_of_tasting = models.TimeField(help_text="Time of the Tasting")
  173. menu_pdf = models.FileField(null=True, upload_to = 'static/tastings/menus/', help_text="If you have a pdf menu, upload it here")
  174. ticket_pdf = models.FileField(null=True, upload_to = 'static/tastings/tickets/', help_text="If you have a pdf of the ticket, upload it here")
  175. tasting_food = models.CharField(max_length=40, choices=FOOD_AT_TASTING, default = 'Wine Only', help_text="Type of food at tasting,")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement