Commit 8e3dd5d3 authored by Robert's avatar Robert
Browse files

Add activities and assignments to api

parent e9679b74
# Generated by Django 2.2.13 on 2020-06-17 08:27
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('commoning', '0003_activity'),
]
operations = [
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user_id', models.IntegerField()),
('activity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='commoning.Activity')),
],
),
]
......@@ -7,6 +7,11 @@ class Activity(models.Model):
need = models.OneToOneField('commoning.Need', on_delete=models.CASCADE)
class Assignment(models.Model):
activity = models.ForeignKey('commoning.Activity', on_delete=models.CASCADE)
user_id = models.IntegerField()
class Need(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
......
from rest_framework import serializers
from commoning.models import Need
from commoning.models import Activity, Assignment, Need
class ActivitySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Activity
fields = ['activity_pattern_url']
class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Assignment
fields = ['activity', 'user_id']
class NeedSerializer(serializers.HyperlinkedModelSerializer):
......
from rest_framework import viewsets
from commoning.models import Need
from commoning.serializers import NeedSerializer
from commoning.models import Activity, Assignment, Need
from commoning.serializers import ActivitySerializer, AssignmentSerializer, NeedSerializer
class ActivityViewSet(viewsets.ModelViewSet):
queryset = Activity.objects.all()
serializer_class = ActivitySerializer
class AssignmentViewSet(viewsets.ModelViewSet):
queryset = Assignment.objects.all()
serializer_class = AssignmentSerializer
class NeedViewSet(viewsets.ModelViewSet):
......
......@@ -5,6 +5,8 @@ from rest_framework import routers
from commoning import views
router = routers.DefaultRouter()
router.register(r'activities', views.ActivityViewSet)
router.register(r'assigments', views.AssignmentViewSet)
router.register(r'needs', views.NeedViewSet)
urlpatterns = [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment