diff --git a/sophon/core/migrations/0004_dataflow.py b/sophon/core/migrations/0004_dataflow.py new file mode 100644 index 0000000..988c49c --- /dev/null +++ b/sophon/core/migrations/0004_dataflow.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1.7 on 2021-04-06 20:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_auto_20210406_0044'), + ] + + operations = [ + migrations.CreateModel( + name='DataFlow', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sdmx_id', models.CharField(help_text='Internal string used in SDMX communication to identify the DataFlow.', max_length=64, verbose_name='SDMX id')), + ('last_update', models.DateTimeField(help_text='The datetime at which the properties of this DataFlow were last updated.', verbose_name='Last updated')), + ('description', models.CharField(help_text='Natural language description of the DataFlow.', max_length=8192, verbose_name='DataFlow description')), + ('datasource_id', models.ForeignKey(help_text='The DataSource this object belongs to.', on_delete=django.db.models.deletion.RESTRICT, to='core.datasource')), + ], + ), + ] diff --git a/sophon/core/models.py b/sophon/core/models.py index 93b9f75..fb34110 100644 --- a/sophon/core/models.py +++ b/sophon/core/models.py @@ -35,6 +35,38 @@ class DataSource(models.Model): return self.pandasdmx_id +class DataFlow(models.Model): + """ + A :class:`.DataFlow` is a object containing the metadata of a SDMX data set. + + See `this page `_ for more details. + """ + + datasource_id = models.ForeignKey( + DataSource, + help_text="The DataSource this object belongs to.", + on_delete=models.RESTRICT, + ) + sdmx_id = models.CharField( + "SDMX id", + help_text="Internal string used in SDMX communication to identify the DataFlow.", + max_length=64, + ) + last_update = models.DateTimeField( + "Last updated", + help_text="The datetime at which the properties of this DataFlow were last updated.", + ) + + description = models.CharField( + "DataFlow description", + help_text="Natural language description of the DataFlow.", + max_length=8192, + ) + + def __str__(self): + return f"{self.datasource_id} | {self.sdmx_id} | {self.description}" + + class Project(models.Model): """ A research :class:`.Project` is a work which may use zero or more :class:`.DataSource`\\ s to prove or disprove an diff --git a/sophon/core/serializers.py b/sophon/core/serializers.py index 7ef6502..7e551b6 100644 --- a/sophon/core/serializers.py +++ b/sophon/core/serializers.py @@ -16,6 +16,22 @@ class DataSourceSerializer(serializers.ModelSerializer): ] +class DataFlowSerializer(serializers.ModelSerializer): + """ + Serializer for :class:`.models.DataFlow` . + """ + + class Meta: + model = models.DataFlow + fields = [ + "id", + "datasource_id", + "sdmx_id", + "last_update", + "description", + ] + + class ProjectSerializer(serializers.ModelSerializer): """ Serializer for :class:`.models.Project` . diff --git a/sophon/core/views.py b/sophon/core/views.py index 1d32128..13787ac 100644 --- a/sophon/core/views.py +++ b/sophon/core/views.py @@ -11,6 +11,15 @@ class ProjectViewSet(viewsets.ModelViewSet): permission_classes = [] +class DataFlowViewSet(viewsets.ModelViewSet): + """ + Viewset for :class:`.models.DataFlow` instances. + """ + queryset = models.DataFlow.objects.all() + serializer_class = serializers.DataFlowSerializer + permission_classes = [] + + class DataSourceViewSet(viewsets.ModelViewSet): """ Viewset for :class:`.models.DataSource` instances.