Parcourir la source

add get for indicatortype

MrOzOn il y a 5 ans
Parent
commit
d85b504f6f

+ 5 - 1
README.md

@@ -25,4 +25,8 @@ Current actions
 `django-admin startapp user ./apps/user`
 3. Create migration
 `python manage.py makemigrations`
-`python manage.py migrate`
+`python manage.py migrate`
+4. Create fixtures data
+`python manage.py dumpdata --format=json indicatortype.IndicatorType > ./apps/indicatortype/fixtures/initial_indicatortype.json`
+5. Load fixtures data
+`python manage.py loaddata --format=json indicatortype.IndicatorType`

+ 0 - 0
apps/indicatortype/__init__.py


+ 13 - 0
apps/indicatortype/admin.py

@@ -0,0 +1,13 @@
+from django.contrib import admin
+
+from apps.indicatortype.models import IndicatorType
+
+
+class IndicatorTypeAdmin(admin.ModelAdmin):
+    fields = ('name', 'mark', 'regexp', 'hint')
+    list_display = ('id', 'name', 'mark', 'regexp', 'hint')
+    # search_fields = ('name',)
+    # ordering = ('-created_date',)
+
+
+admin.site.register(IndicatorType, IndicatorTypeAdmin)

+ 5 - 0
apps/indicatortype/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class UserConfig(AppConfig):
+    name = 'user'

+ 1 - 0
apps/indicatortype/fixtures/initial_indicatortype.json

@@ -0,0 +1 @@
+[{"model": "indicatortype.indicatortype", "pk": 1, "fields": {"name": "\u0422\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430", "mark": "\u00b0C", "regexp": "[3|4]\\\\d(\\\\.\\\\d)?", "hint": "36.6"}}, {"model": "indicatortype.indicatortype", "pk": 2, "fields": {"name": "\u0414\u0430\u0432\u043b\u0435\u043d\u0438\u0435", "mark": "\u043c\u043c \u0440\u0442.\u0441\u0442.", "regexp": "\\\\d{2,3}\\\\/\\\\d{2}", "hint": "120/70"}}, {"model": "indicatortype.indicatortype", "pk": 3, "fields": {"name": "\u041f\u0443\u043b\u044c\u0441", "mark": "\u0443\u0434./\u043c\u0438\u043d", "regexp": "\\\\d{2,3}", "hint": "120"}}]

+ 28 - 0
apps/indicatortype/migrations/0001_initial.py

@@ -0,0 +1,28 @@
+# Generated by Django 3.0.8 on 2020-07-23 13:38
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='IndicatorType',
+            fields=[
+                ('id', models.AutoField(primary_key=True, serialize=False)),
+                ('name', models.CharField(max_length=50)),
+                ('mark', models.CharField(max_length=5)),
+                ('regexp', models.CharField(max_length=100)),
+                ('hint', models.CharField(max_length=50)),
+            ],
+            options={
+                'verbose_name': 'Тип измерения',
+                'verbose_name_plural': 'Типы измерений',
+            },
+        ),
+    ]

+ 18 - 0
apps/indicatortype/migrations/0002_auto_20200723_1641.py

@@ -0,0 +1,18 @@
+# Generated by Django 3.0.8 on 2020-07-23 13:41
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('indicatortype', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='indicatortype',
+            name='mark',
+            field=models.CharField(max_length=20),
+        ),
+    ]

+ 0 - 0
apps/indicatortype/migrations/__init__.py


+ 18 - 0
apps/indicatortype/models.py

@@ -0,0 +1,18 @@
+from django.db import models
+
+
+class IndicatorType(models.Model):
+    """ Модель (сущность) - Тип измерения """
+    id = models.AutoField(primary_key=True)
+    name = models.CharField(max_length=50)
+    mark = models.CharField(max_length=20)
+    regexp = models.CharField(max_length=100)
+    hint = models.CharField(max_length=50)
+
+    def __str__(self):
+        # return "Тип измерения № %s - %s" % (self.id, self.name,)
+        return "%s" % (self.name,)
+
+    class Meta:
+        verbose_name = "Тип измерения"
+        verbose_name_plural = "Типы измерений"

+ 11 - 0
apps/indicatortype/serializers.py

@@ -0,0 +1,11 @@
+from rest_framework import serializers, status
+from rest_framework.exceptions import ValidationError
+
+from apps.indicatortype.models import IndicatorType
+from apps.patient.models import Patient
+
+
+class IndicatorTypeSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = IndicatorType
+        fields = '__all__'

+ 3 - 0
apps/indicatortype/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 10 - 0
apps/indicatortype/views.py

@@ -0,0 +1,10 @@
+from django.shortcuts import render
+from rest_framework import viewsets
+
+from apps.indicatortype.models import IndicatorType
+from apps.indicatortype.serializers import IndicatorTypeSerializer
+
+
+class IndicatorTypeViewSet(viewsets.ReadOnlyModelViewSet):
+    queryset = IndicatorType.objects.all()
+    serializer_class = IndicatorTypeSerializer

+ 1 - 0
healthdiarybackend/settings.py

@@ -44,6 +44,7 @@ INSTALLED_APPS = [
     'rest_framework',
     'rest_framework.authtoken',
     'apps.patient',
+    'apps.indicatortype',
 ]
 
 MIDDLEWARE = [

+ 2 - 0
healthdiarybackend/urls.py

@@ -21,12 +21,14 @@ from rest_framework import routers
 from apps.patient.models import Patient
 from apps.user import views as user_views
 from apps.patient import views as patient_views
+from apps.indicatortype import views as indicatortype_views
 
 from apps.user.serializers import CustomAuthToken
 
 router = routers.DefaultRouter()
 router.register(r'users', user_views.UserViewSet)
 router.register(r'patients', patient_views.PatientViewSet, Patient)
+router.register(r'indicatortype', indicatortype_views.IndicatorTypeViewSet)
 
 urlpatterns = [
     path('', include(router.urls)),