X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/53907d17526cecf92207417e051527c00bcd2426..3fd04fa811ccc4be2c8f949d06faef9b0325a393:/wtem/models.py diff --git a/wtem/models.py b/wtem/models.py index 75fa0ba..90492bf 100644 --- a/wtem/models.py +++ b/wtem/models.py @@ -2,6 +2,10 @@ import random import string from django.db import models +from django.contrib.auth.models import User +from django.core.exceptions import ValidationError +from django.utils.translation import ugettext as _ +from jsonfield import JSONField from contact.models import Contact @@ -41,4 +45,16 @@ class Submission(models.Model): class Attachment(models.Model): submission = models.ForeignKey(Submission) name = models.CharField(max_length=100) - file = models.FileField(upload_to = 'wtem/attachment') \ No newline at end of file + file = models.FileField(upload_to = 'wtem/attachment') + + +class Assignment(models.Model): + user = models.ForeignKey(User) + exercises = JSONField() + + def clean(self): + if not isinstance(self.exercises, list): + raise ValidationError(_('Assigned exercises must be declared in a list format')) + for exercise in self.exercises: + if not isinstance(exercise, int) or exercise < 1: + raise ValidationError(_('Invalid exercise id: %s' % exercise))