from django.db import models from django.contrib.auth.models import User from django.utils import html import datetime # Create your models here. # jorge schema 2010-06-07: # Item, cost of goods, location of damage on the item, how the damage # occurred, type of damage, date of damage, location of item now # # franklin schema 2009-02-10: # item name # vendor # date of damage/discovery # who damaged # how did damage happen # what is the damage # is it being repaired, yes/no # is it being claimed # where is it physically? # resolution # There needs to be an automatic email sent to Daniel and Murray when something is entered. # perhaps with: http://docs.djangoproject.com/en/1.1/ref/signals/#django.db.models.signals.pre_save # # miles schema 2010-06-25 #when entered DateTimeField(auto_now_add=True) (hidden somehow?) #who entered ForeignKey(User???) #when discovered DateTimeField(auto_now_add=True) #SKU / inventory id PositiveIntegerField # autofill if unique: "Product name(128) / mid#" CharField(max_length=145) # SELECT # m.name, m.id # FROM # product_inventory pi # JOIN models m ON (pi.model_id = m.id) # WHERE # pi.id = AND m.void = 'n' # autofill: SKU label CharField(255) # autofill: manufacturer CharField(64) # SELECT # ma.name, it.label # FROM # product_inventory pi # JOIN inventory_types it ON (it.id = pi.inventory_type_id) # JOIN manufacturers ma ON (ma.id = it.manufacturer_id) # WHERE # pi.id = # autofill if unique: vendor CharField(max_length=64), cogs at damage time DecimalField(max_digits=8, decimal_places=2) # SELECT # v.name, sv.default_cost # FROM # product_inventory pi # JOIN inventory_types it ON (it.id = pi.inventory_type_id) # JOIN sku_vendors sv ON (sv.sku_id = it.id) # JOIN vendors v ON (sv.vendor_id = v.id) # WHERE # pi.id = AND sv.status = 'active' #who ForeignKey(User???) #who EmailField #how TextField #resolution history # when DateTimeField(auto_now=True) # type: ( choices=(('repair', 'being repaired'), ('insurance', 'insurance claim'), ('final', 'resolved.'),) ) # polarity: BooleanField # comment CharField(max_length=128, blank=True) #location history # when DateTimeField(auto_now=True) # last known location CharField(max_length=128) class Injury(models.Model): enter_when = models.DateTimeField(help_text=html.escape("not editable.")) enter_who = models.ForeignKey(User, related_name='enter_who_injury_set', help_text=html.escape("not editable.")) discover_when = models.DateTimeField(help_text=html.escape("when the damage was discovered")) model_name = models.CharField(max_length=145, blank=True, null=True) #XXXsignal sku = models.PositiveIntegerField() sku_label = models.CharField(max_length=255, blank=True, null=True) #XXXsignal manufacturer = models.CharField(max_length=64, blank=True, null=True) #XXXsignal vendor = models.CharField(max_length=64, blank=True, null=True) #XXXsignal cogs_when_entered = models.DecimalField(max_digits=8, decimal_places=2, blank=True, null=True) #XXXsignal who = models.ForeignKey(User, related_name='who_injury_set', blank=True, null=True, help_text=html.escape("who damaged the thing, if it was one of us. blank for shipping/storage damage.")) # Injury.who.email might do rather than storing email addresses here. how = models.TextField(blank=True, null=True) def save(self): if not self.id: self.enter_when = datetime.datetime.today() super(Injury, self).save() class ResolutionHist(models.Model): injury = models.ForeignKey(Injury) enter_who = models.ForeignKey(User, help_text=html.escape("not editable.")) enter_when = models.DateTimeField(help_text=html.escape("not editable.")) type = models.CharField(max_length=10, choices=( ('repair', 'being repaired'), ('insurance', 'insurance claim'), ('final', 'resolved.'), ) ) polarity = models.NullBooleanField(choices=((True, 'yes'), (False, 'no')), help_text=html.escape("check for positive-trending resolution like can repair, can recover insurance. Or, uncheck for tried-but-can't."), blank=True, null=True) comment = models.CharField(max_length=128, blank=True) def save(self): if not self.id: self.enter_when = datetime.datetime.today() super(ResolutionHist, self).save() class LocationHist(models.Model): injury = models.ForeignKey(Injury) enter_who = models.ForeignKey(User, help_text=html.escape("not editable.")) enter_when = models.DateTimeField(help_text=html.escape("not editable.")) where = models.CharField(max_length=128) def save(self): if not self.id: self.enter_when = datetime.datetime.today() super(LocationHist, self).save() # TODO # how to make editable=False fields show up for context # save() or init() or signal?: enter_when and enter_who need to be the User working on the model # signals: post_save needs to send an email # http://docs.djangoproject.com/en/1.1/ref/models/instances/#what-happens-when-you-save STEP 2 # signal or can I override save() method? need to populate all the stuff pulled from coresense.