Only allow one default cluster station or sequencer to be set
authorDiane Trout <diane@caltech.edu>
Wed, 27 Jun 2012 22:56:37 +0000 (15:56 -0700)
committerDiane Trout <diane@caltech.edu>
Wed, 27 Jun 2012 22:56:37 +0000 (15:56 -0700)
Works by watching for the pre_save signal for those classes
and if it sees that the isdefault flag being set to true it
goes through all the other records and sets isdefault to null.

htsworkflow/frontend/experiments/models.py

index 20131e41bb22170cd720e4b93e934b4a9787e786..1b3674c2a3930fc5d382b5ed204ba9f2e1e7bd80 100644 (file)
@@ -71,7 +71,7 @@ class ClusterStation(models.Model):
         """Clear default if needed
         """
         if instance.isdefault:
-            for c in ClusterStation.objects.all():
+            for c in ClusterStation.objects.filter(isdefault=True).all():
                 if c.id != instance.id:
                     c.isdefault = False
                     c.save()
@@ -118,7 +118,7 @@ class Sequencer(models.Model):
         """Clear default if needed
         """
         if instance.isdefault:
-            for s in Sequencer.objects.all():
+            for s in Sequencer.objects.filter(isdefault=True).all():
                 if s.id != instance.id:
                     s.isdefault = False
                     s.save()