Skip to content

Commit

Permalink
serializers afgewerkt
Browse files Browse the repository at this point in the history
  • Loading branch information
sPAICEcake committed Mar 10, 2024
1 parent 2f966bb commit f96406a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/models/indiening.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Indiening(models.Model):
indiener = models.ForeignKey('Groep', on_delete=models.CASCADE)
indieningsbestanden = models.FileField(upload_to='uploads/')
tijdstip = models.DateTimeField(null=False)
project = models.ForeignKey('Project', on_delete=models.CASCADE)
project = models.ForeignKey('Project', on_delete=models.CASCADE, default='0')

def __str__(self):
return self.tijdstip
Expand Down
9 changes: 8 additions & 1 deletion api/serializers/indiening.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ class Meta:
fields = '__all__'

def create(self, validated_data):
return Indiening.objects.create(**validated_data)
# indiener is een groep, dus zeker student(en)
indiening = Indiening.objects.create(**validated_data)
return indiening

def update(self, instance, validated_data):
instance = Indiening.objects.create(**validated_data)
instance.save()
return instance
28 changes: 27 additions & 1 deletion api/serializers/project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
from rest_framework import serializers
from api.models.project import Project

from datetime import datetime


class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = '__all__'
fields = '__all__'

def create(self, validated_data):
deadline = validated_data.pop('deadline')

validate_deadline(deadline)

project = Project.objects.create(**validated_data)
project.deadline.set(deadline)
return project

def update(self, instance, validated_data):
deadline = validated_data.pop('deadline')

validate_deadline(deadline)

instance = Project.objects.create(**validated_data)
instance.deadline.set(deadline)
instance.save()
return instance


def validate_deadline(deadline):
if deadline <= datetime.now():
raise serializers.ValidationError("Deadline moet in de toekomst liggen")
8 changes: 7 additions & 1 deletion api/serializers/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ class Meta:
fields = '__all__'

def create(self, validated_data):
return Score.objects.create(**validated_data)
score = Score.objects.create(**validated_data)
return score

def update(self, instance, validated_data):
instance = Score.objects.create(**validated_data)
instance.save()
return instance

0 comments on commit f96406a

Please sign in to comment.