Advertisement
Guest User

Untitled

a guest
May 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. from datetime import timedelta
  2.  
  3. from django.db import models
  4. from django.db.models import Max, Sum
  5. from django.utils.text import slugify
  6.  
  7. from inventory.models import AdSlot
  8.  
  9.  
  10. # Create your models here.
  11. class Campaign(models.Model):
  12. book_title = models.CharField(max_length=255)
  13. date_created = models.DateField(auto_now_add=True)
  14. date_updated = models.DateField(auto_now=True)
  15. internal_design = models.BooleanField()
  16. order = models.ForeignKey('Order')
  17. start_date = models.DateField()
  18.  
  19. @property
  20. def ad_design_price(self):
  21. """ Get the sum of all ad design costs in the products for this campaign """
  22. print(self.product_set.all())
  23. return self.product_set.all().aggregate(total=Sum('price'))['total']
  24.  
  25. @property
  26. def ad_deadline(self):
  27. """ Get the distance between the start date and the earliest ad deadline. """
  28. delta = self.product_set.aggregate(Max('ad_deadline'))['ad_deadline__max']
  29. return self.start_date - timedelta(days=delta)
  30.  
  31.  
  32. class Product(models.Model):
  33. campaign = models.ForeignKey('Campaign')
  34. date_created = models.DateField(auto_now_add=True)
  35. date_updated = models.DateField(auto_now=True)
  36. product_type = models.ForeignKey('ProductType')
  37. run_length = models.IntegerField()
  38. #ad_slot = models.ForeignKey('AdSlot')
  39.  
  40.  
  41. class ProductType(models.Model):
  42. UNKNOWN = 'UNKNOWN'
  43. WEB = 'WEB'
  44. PRINT = 'PRINT'
  45. MOBILE = 'MOBILE'
  46. EMAIL = 'EMAIL'
  47. BILLBOARD = 'BILLBOARD'
  48.  
  49. MEDIUM_CHOICES = (
  50. (UNKNOWN, 'Unknown'),
  51. (WEB, 'Web'),
  52. (PRINT, 'Print'),
  53. (EMAIL, 'Email/Newsletter'),
  54. (BILLBOARD, 'Billboard'),
  55. )
  56.  
  57. RUNLENGTH_CHOICES = (
  58. ('ISSUES', 'Issues'),
  59. ('WEEKS', 'Weeks'),
  60. )
  61.  
  62. medium = models.CharField(max_length=50, choices=MEDIUM_CHOICES)
  63. name = models.CharField(max_length=255, )
  64. price = models.DecimalField(max_digits=8, decimal_places=2)
  65. run_length_period = models.CharField(max_length=50, choices=RUNLENGTH_CHOICES)
  66. slug = models.SlugField(unique=True)
  67. ad_deadline = models.IntegerField()
  68.  
  69. def __str__(self):
  70. return self.name
  71.  
  72. def save(self, **kwargs):
  73. if not self.slug:
  74. self.slug = slugify(self.name)
  75. super().save(**kwargs)
  76.  
  77. @property
  78. def price(self):
  79. return "${}".format(self.price)
  80.  
  81.  
  82. # Three Customer Types
  83. class Customer(models.Model):
  84. # Add demographic information, payment information
  85. pass
  86.  
  87. class Order(models.Model):
  88. customer = models.ForeignKey('Customer')
  89. paid = models.BooleanField(default=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement