Turn the library_id back into the primary key for samples_library (SCHEMA CHANGE!)
[htsworkflow.git] / htsworkflow / frontend / experiments / admin.py
index a4a1eef424ebedc0b2877c4a7a1ceaff1f985752..0f00d0eea8732e7614c520f708e92c5665376dfd 100644 (file)
@@ -1,36 +1,24 @@
 from htsworkflow.frontend.experiments.models import FlowCell, DataRun, ClusterStation, Sequencer, Lane
 from django.contrib import admin
+from django.contrib.admin.widgets import FilteredSelectMultiple
 from django.forms import ModelForm
-from django.forms.fields import CharField
+from django.forms.fields import Field, CharField
 from django.forms.widgets import TextInput
 from django.utils.translation import ugettext_lazy as _
 
-
-class LaneForm(ModelForm):
-    comment = CharField(widget=TextInput(attrs={'size':'80'}), required=False)
-    
-    class Meta:
-        model = Lane
-
-class LaneInline(admin.StackedInline):
-  model = Lane
-  max_num = 8
-  extra = 8
-  form = LaneForm
-
 class DataRunOptions(admin.ModelAdmin):
   search_fields = [
       'run_folder',
       'run_note',
       'config_params',
-      '=fcid__lane_1_library__library_id',
-      '=fcid__lane_2_library__library_id',
-      '=fcid__lane_3_library__library_id',
-      '=fcid__lane_4_library__library_id',
-      '=fcid__lane_5_library__library_id',
-      '=fcid__lane_6_library__library_id',
-      '=fcid__lane_7_library__library_id',
-      '=fcid__lane_8_library__library_id'
+      '=fcid__lane_1_library__id',
+      '=fcid__lane_2_library__id',
+      '=fcid__lane_3_library__id',
+      '=fcid__lane_4_library__id',
+      '=fcid__lane_5_library__id',
+      '=fcid__lane_6_library__id',
+      '=fcid__lane_7_library__id',
+      '=fcid__lane_8_library__id'
       'fcid__lane_1_library__library_name',
       'fcid__lane_2_library__library_name',
       'fcid__lane_3_library__library_name',
@@ -48,22 +36,65 @@ class DataRunOptions(admin.ModelAdmin):
   ]
   list_filter = ('run_status', 'run_start_time')
 
+# lane form setup needs to come before Flowcell form config
+# as flowcell refers to the LaneInline class
+class LaneForm(ModelForm):
+    comment = CharField(widget=TextInput(attrs={'size':'80'}), required=False)
+    
+    class Meta:
+        model = Lane
+
+class LaneInline(admin.StackedInline):
+    """
+    Controls display of Lanes on the Flowcell form.
+    """
+    model = Lane
+    max_num = 8
+    extra = 8
+    form = LaneForm
+    raw_id_fields = ('library',)
+    fieldsets = (
+      (None, {
+        'fields': ('lane_number', 'flowcell',
+                   ('library',),
+                   ('pM', 'cluster_estimate'),
+                   'comment',)
+      }),
+    )
+
+class LaneOptions(admin.ModelAdmin):
+    """
+    Controls display of Lane browser
+    """
+    list_display = ('flowcell', 'lane_number', 'library', 'comment')
+    fieldsets = (
+      (None, {
+        'fields': ('lane_number', 'flowcell',
+                   ('library'),
+                   ('pM', 'cluster_estimate'))
+      }),
+      ('Optional', {
+        'classes': ('collapse', ),
+        'fields': ('comment', )
+      }),
+    )
+    
 class FlowCellOptions(admin.ModelAdmin):
     date_hierarchy = "run_date"
     save_on_top = True
     search_fields = ('flowcell_id',
         'sequencer__name',
         'cluster_station__name',
-        '=lane__library__library_id',
+        '=lane__library__id',
         'lane__library__library_name')
     list_display = ('flowcell_id','run_date','Lanes')
     list_filter = ('sequencer','cluster_station')
     fieldsets = (
         (None, {
-            'fields': ('run_date', ('flowcell_id','cluster_station','sequencer'), ('read_length', 'paired_end'),)
+            'fields': ('run_date', ('flowcell_id','cluster_station','sequencer'), ('read_length', 'control_lane', 'paired_end'),)
         }),
         #('Lanes:', {
-        #   'fields' : (('lane__library__library_id', 'lane__pM', 'lane__cluster_estimate'),)
+        #   'fields' : (('lane__library__id', 'lane__pM', 'lane__cluster_estimate'),)
         #}),
         ('Notes:', { 'fields': ('notes',),}),
     )
@@ -79,18 +110,6 @@ class SequencerOptions(admin.ModelAdmin):
     list_display = ('name', )
     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
     
-class LaneOptions(admin.ModelAdmin):
-    list_display = ('flowcell', 'lane_number', 'library', 'comment')
-    fieldsets = (
-      (None, {
-        'fields': ('lane_number', 'flowcell', 'library', 'pM', 'cluster_estimate')
-      }),
-      ('Optional', {
-        'classes': ('collapse', ),
-        'fields': ('comment', )
-      }),
-    )
-    
 
 admin.site.register(DataRun, DataRunOptions)
 admin.site.register(FlowCell, FlowCellOptions)