added Affiliation table and linked to Library in a ManyToMany relathionship
authorRami Rauch <rrauch@stanford.edu>
Mon, 25 Aug 2008 22:13:01 +0000 (22:13 +0000)
committerRami Rauch <rrauch@stanford.edu>
Mon, 25 Aug 2008 22:13:01 +0000 (22:13 +0000)
htswfrontend/htswfrontend/fctracker/models.py

index d7f2209e8da540adb8876af761fcc5be094a136e..3ca4ac13421c0aa011534eb9c5b2f49ace74291f 100644 (file)
@@ -33,7 +33,7 @@ class Antibody(models.Model):
     verbose_name_plural = "antibodies"
     ordering = ["antigene"]
   class Admin:
-      list_display = ('antigene','antibodies','catalog','source','biology','notes')
+      list_display = ('antigene','nickname','antibodies','catalog','source','biology','notes')
       list_filter = ('antibodies','source')
       fields = (
         (None, {
@@ -94,6 +94,28 @@ class Species(models.Model):
         }),
       )
 
+class Affiliation(models.Model):
+  name = models.CharField(max_length=256, db_index=True, core=True,verbose_name='Group Name')
+  contact = models.CharField(max_length=256, null=True, blank=True,verbose_name='Contact Name')  
+  email = models.EmailField(null=True,blank=True)
+  
+  def __str__(self):
+    str = self.name
+    if self.contact != '':
+      str += ' ('+self.contact+')' 
+    return str
+
+  class Meta:
+    ordering = ["name","contact"]
+    unique_together = (("name", "contact"),)
+
+  class Admin:
+      list_display = ('name','contact','email')
+      fields = (
+        (None, {
+            'fields': (('name','contact','email'))
+        }),
+      )
 
 class Library(models.Model):
   library_id = models.CharField(max_length=30, unique=True, db_index=True, core=True)
@@ -102,7 +124,8 @@ class Library(models.Model):
   cell_line = models.ForeignKey(Cellline,core=True)
   condition = models.ForeignKey(Condition,core=True)
   antibody = models.ForeignKey(Antibody,blank=True,null=True,core=True)
-
+  # New field Aug/25/08. SQL: alter table fctracker_library add column "lib_affiliation" varchar(256)  NULL;
+  affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True,filter_interface=models.HORIZONTAL)
   # New field Aug/19/08
   # SQL to add column: alter table fctracker_library add column "replicate" smallint unsigned NULL;
   REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4))
@@ -152,12 +175,20 @@ class Library(models.Model):
   def antibody_name(self):
     return self.antibody.nickname
 
+  def affiliation(self):
+    affs = self.affiliations.all().order_by('name')
+    tstr = ''
+    ar = []
+    for t in affs:
+        ar.append(t.__str__())
+    return '%s' % (", ".join(ar))
+
   class Admin:
     date_hierarchy = "creation_date"
     save_as = True
     save_on_top = True
-    search_fields = ['library_name', 'library_id','made_by','made_for','antibody__antigene','antibody__catalog','antibody__antibodies','antibody__source','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
-    list_display = ('library_id', 'library_name','experiment_type','replicate','antibody_name','cell_line','made_by','creation_date')
+    search_fields = ['affiliation','library_name', 'library_id','made_by','made_for','antibody__antigene','antibody__catalog','antibody__antibodies','antibody__source','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
+    list_display = ('affiliation','library_id', 'library_name','experiment_type','replicate','antibody_name','cell_line','made_by','creation_date')
     list_display_links = ('library_id', 'library_name')
     list_filter = ('experiment_type','library_species','made_for', 'made_by','replicate')
     fields = (
@@ -167,4 +198,7 @@ class Library(models.Model):
         ('Creation Information:', {
             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
         }),
+        ('Library/Project Affiliation:', {
+            'fields' : (('affiliations'),)
+        }),
         )