Explorar el Código

fix model for indicators

MrOzOn hace 5 años
padre
commit
70ecb0f454

+ 23 - 0
apps/indicator/migrations/0003_auto_20201203_1302.py

@@ -0,0 +1,23 @@
+# Generated by Django 3.0.8 on 2020-12-03 10:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('indicator', '0002_indicator_created_date'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='indicator',
+            name='value1',
+            field=models.CharField(max_length=15),
+        ),
+        migrations.AlterField(
+            model_name='indicator',
+            name='value2',
+            field=models.CharField(blank=True, max_length=15, null=True),
+        ),
+    ]

+ 2 - 2
apps/indicator/models.py

@@ -6,8 +6,8 @@ class Indicator(models.Model):
     """ Модель (сущность) - Измерение """
     id = models.AutoField(primary_key=True)
     type = models.ForeignKey('indicatortype.IndicatorType', on_delete=models.CASCADE)
-    value1 = models.DecimalField(max_digits=8, decimal_places=3)
-    value2 = models.DecimalField(max_digits=8, decimal_places=3, blank=True, null=True)
+    value1 = models.CharField(max_length=15)
+    value2 = models.CharField(max_length=15, blank=True, null=True)
     value_added = models.DateTimeField()
     patient = models.ForeignKey('patient.Patient', on_delete=models.CASCADE)
     last_modified = models.DateTimeField(auto_now=True)

+ 2 - 2
apps/indicator/views.py

@@ -11,7 +11,7 @@ class IndicatorViewSet(viewsets.ModelViewSet):
 
     def get_queryset(self):
         user = self.request.user
-        return Indicator.objects.filter(patient__owners=user)
+        return Indicator.objects.filter(patient__owners=user).order_by('-value_added')
     # queryset = Patient.objects.all().order_by('-created_date')
 
     # def get_object(self):
@@ -26,7 +26,7 @@ class IndicatorViewSet(viewsets.ModelViewSet):
 
     serializer_class = IndicatorSerializer
     filter_backends = [DjangoFilterBackend]
-    filterset_fields = ['type']
+    filterset_fields = ['type', 'patient']
 
 
 # https://www.django-rest-framework.org/api-guide/filtering/