From: Brandon King Date: Fri, 29 May 2009 23:00:04 +0000 (+0000) Subject: First attempt at an inventory tracking database X-Git-Tag: 0.2.0.5~7 X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=a60590cc89af6611dc5fd01bf36f766b8377228a First attempt at an inventory tracking database * Includes a LongTermStorage object which links flowcells/libraries to storage items. --- diff --git a/htsworkflow/frontend/inventory/__init__.py b/htsworkflow/frontend/inventory/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/htsworkflow/frontend/inventory/admin.py b/htsworkflow/frontend/inventory/admin.py new file mode 100644 index 0000000..70e12b8 --- /dev/null +++ b/htsworkflow/frontend/inventory/admin.py @@ -0,0 +1,28 @@ +from django.contrib import admin + +from htsworkflow.frontend.inventory.models import Item, ItemInfo, ItemType, Vendor, Location, LongTermStorage + +class ItemAdmin(admin.ModelAdmin): + list_display = ('uuid', 'barcode_id','item_type', 'item_info', 'location', 'force_use_uuid', 'creation_date') + +class ItemInfoAdmin(admin.ModelAdmin): + pass + +class ItemTypeAdmin(admin.ModelAdmin): + pass + +class VendorAdmin(admin.ModelAdmin): + pass + +class LocationAdmin(admin.ModelAdmin): + pass + +class LongTermStorageAdmin(admin.ModelAdmin): + pass + +admin.site.register(Item, ItemAdmin) +admin.site.register(ItemInfo, ItemInfoAdmin) +admin.site.register(ItemType, ItemTypeAdmin) +admin.site.register(Vendor, VendorAdmin) +admin.site.register(Location, LocationAdmin) +admin.site.register(LongTermStorage, LongTermStorageAdmin) diff --git a/htsworkflow/frontend/inventory/models.py b/htsworkflow/frontend/inventory/models.py new file mode 100644 index 0000000..26781ee --- /dev/null +++ b/htsworkflow/frontend/inventory/models.py @@ -0,0 +1,105 @@ +from django.db import models +from django.db.models.signals import pre_save + +from htsworkflow.frontend.samples.models import Library +from htsworkflow.frontend.experiments.models import FlowCell + + +import uuid + +def _assign_uuid(sender, instance, **kwargs): + """ + Assigns a UUID to model on save + """ + print 'Entered _assign_uuid' + if instance.uuid is None or len(instance.uuid) != 32: + instance.uuid = uuid.uuid1().hex + + +class Vendor(models.Model): + name = models.CharField(max_length=256) + url = models.URLField(blank=True, null=True) + + def __unicode__(self): + return u"%s" % (self.name) + + +class Location(models.Model): + + name = models.CharField(max_length=256, unique=True) + location_description = models.TextField() + + uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation") + + notes = models.TextField(blank=True, null=True) + + def __unicode__(self): + if len(self.location_description) > 16: + return u"%s: %s" % (self.name, self.location_description[0:16]+u"...") + else: + return u"%s: %s" % (self.name, self.location_description) + +pre_save.connect(_assign_uuid, sender=Location) + +class ItemInfo(models.Model): + model_id = models.CharField(max_length=256) + model_url = models.URLField(blank=True, null=True) + + qty_purchased = models.IntegerField(default=1) + + vendor = models.ForeignKey(Vendor) + purchase_date = models.DateField(blank=True, null=True) + warranty_months = models.IntegerField(blank=True, null=True) + + def __unicode__(self): + return u"%s: %s" % (self.model_id, self.purchase_date) + + +class ItemType(models.Model): + + name = models.CharField(max_length=64, unique=True) + description = models.TextField(blank=True, null=True) + + def __unicode__(self): + return u"%s" % (self.name) + + +class Item(models.Model): + + item_type = models.ForeignKey(ItemType) + + #Automatically assigned uuid; used for barcode if one is not provided in + # barcode_id + uuid = models.CharField(max_length=32, blank=True, help_text="Leave blank for automatic UUID generation") + + # field for existing barcodes; used instead of uuid if provided + barcode_id = models.CharField(max_length=256, blank=True, null=True) + force_use_uuid = models.BooleanField(default=False) + + item_info = models.ForeignKey(ItemInfo) + + location = models.ForeignKey(Location) + + creation_date = models.DateTimeField(auto_now_add=True) + modified_date = models.DateTimeField(auto_now=True) + + notes = models.TextField(blank=True, null=True) + + def __unicode__(self): + if self.barcode_id is None or len(self.barcode_id) == 0: + return u"invu|%s" % (self.uuid) + else: + return u"invb|%s" % (self.barcode_id) + +pre_save.connect(_assign_uuid, sender=Item) + + +class LongTermStorage(models.Model): + + flowcell = models.ForeignKey(FlowCell) + libraries = models.ManyToManyField(Library) + + storage_devices = models.ManyToManyField(Item) + + def __unicode__(self): + return u"%s: %s" % (str(self.flowcell), ', '.join([ str(s) for s in self.storage_devices.iterator() ])) \ No newline at end of file diff --git a/htsworkflow/frontend/inventory/views.py b/htsworkflow/frontend/inventory/views.py new file mode 100644 index 0000000..60f00ef --- /dev/null +++ b/htsworkflow/frontend/inventory/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/htsworkflow/frontend/settings.py b/htsworkflow/frontend/settings.py index eb30b90..9986f79 100644 --- a/htsworkflow/frontend/settings.py +++ b/htsworkflow/frontend/settings.py @@ -153,6 +153,7 @@ INSTALLED_APPS = ( 'htsworkflow.frontend.experiments', 'htsworkflow.frontend.analysis', 'htsworkflow.frontend.reports', + 'htsworkflow.frontend.inventory', 'django.contrib.databrowse', )