From fa7235ea8f084c37014bf69351ef677d10f4eacd Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Mon, 6 Apr 2020 14:14:24 +0200
Subject: [PATCH] added indices to table

---
 .../web/migrations/0150_auto_20200406_1144.py | 19 +++++++++++++++++++
 .../web/migrations/0151_auto_20200406_1207.py | 19 +++++++++++++++++++
 smash/web/models/provenance.py                |  1 +
 smash/web/models/study_subject.py             |  2 +-
 smash/web/models/subject.py                   |  2 +-
 5 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 smash/web/migrations/0150_auto_20200406_1144.py
 create mode 100644 smash/web/migrations/0151_auto_20200406_1207.py

diff --git a/smash/web/migrations/0150_auto_20200406_1144.py b/smash/web/migrations/0150_auto_20200406_1144.py
new file mode 100644
index 00000000..3f806628
--- /dev/null
+++ b/smash/web/migrations/0150_auto_20200406_1144.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.5 on 2020-04-06 11:44
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('web', '0149_auto_20200406_0926'),
+    ]
+
+    operations = [
+        migrations.AlterIndexTogether(
+            name='provenance',
+            index_together=set([('modified_table', 'modified_table_id')]),
+        ),
+    ]
diff --git a/smash/web/migrations/0151_auto_20200406_1207.py b/smash/web/migrations/0151_auto_20200406_1207.py
new file mode 100644
index 00000000..630fa020
--- /dev/null
+++ b/smash/web/migrations/0151_auto_20200406_1207.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.5 on 2020-04-06 12:07
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('web', '0150_auto_20200406_1144'),
+    ]
+
+    operations = [
+        migrations.AlterIndexTogether(
+            name='provenance',
+            index_together=set([('modified_table', 'modified_table_id', 'modification_date')]),
+        ),
+    ]
diff --git a/smash/web/models/provenance.py b/smash/web/models/provenance.py
index 0d9aeb7a..79e1f665 100644
--- a/smash/web/models/provenance.py
+++ b/smash/web/models/provenance.py
@@ -5,6 +5,7 @@ from django.db import models
 class Provenance(models.Model):
     class Meta:
         app_label = 'web'
+        index_together = ['modified_table', 'modified_table_id', 'modification_date']
 
 
     modified_table = models.CharField(max_length=1024,
diff --git a/smash/web/models/study_subject.py b/smash/web/models/study_subject.py
index 80d2f8ea..0fe4b5c4 100644
--- a/smash/web/models/study_subject.py
+++ b/smash/web/models/study_subject.py
@@ -17,7 +17,7 @@ class StudySubject(models.Model):
 
     @property
     def provenances(self):
-      return Provenance.objects.filter(modified_table=StudySubject._meta.db_table).filter(modified_table_id=self.id).order_by('-modification_date')
+      return Provenance.objects.filter(modified_table=StudySubject._meta.db_table, modified_table_id=self.id).order_by('-modification_date')
 
     def finish_all_visits(self):
         visits = Visit.objects.filter(subject=self, is_finished=False)
diff --git a/smash/web/models/subject.py b/smash/web/models/subject.py
index 22b45738..5a323cbe 100644
--- a/smash/web/models/subject.py
+++ b/smash/web/models/subject.py
@@ -17,7 +17,7 @@ class Subject(models.Model):
     
     @property
     def provenances(self):
-      return Provenance.objects.filter(modified_table=Subject._meta.db_table).filter(modified_table_id=self.id).order_by('-modification_date')
+        return Provenance.objects.filter(modified_table=Subject._meta.db_table, modified_table_id=self.id).order_by('-modification_date')
 
     sex = models.CharField(max_length=1,
                            choices=SEX_CHOICES,
-- 
GitLab