|
@ -1,6 +1,7 @@ |
|
|
import uuid |
|
|
import uuid |
|
|
|
|
|
|
|
|
from django.contrib.auth.models import User |
|
|
from django.contrib.auth.models import User |
|
|
|
|
|
from django.core.exceptions import ValidationError |
|
|
from django.db import models |
|
|
from django.db import models |
|
|
from django_drf_filepond.models import DrfFilePondStoredStorage |
|
|
from django_drf_filepond.models import DrfFilePondStoredStorage |
|
|
|
|
|
|
|
@ -37,6 +38,29 @@ class Example(models.Model): |
|
|
ordering = ["created_at"] |
|
|
ordering = ["created_at"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Assignment(models.Model): |
|
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) |
|
|
|
|
|
project = models.ForeignKey(to=Project, on_delete=models.CASCADE, related_name="assignments") |
|
|
|
|
|
example = models.ForeignKey(to=Example, on_delete=models.CASCADE, related_name="assignments") |
|
|
|
|
|
assignee = models.ForeignKey(to=User, on_delete=models.CASCADE) |
|
|
|
|
|
created_at = models.DateTimeField(auto_now_add=True, db_index=True) |
|
|
|
|
|
updated_at = models.DateTimeField(auto_now=True) |
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
|
unique_together = (("example", "assignee"),) |
|
|
|
|
|
|
|
|
|
|
|
def clean(self): |
|
|
|
|
|
# assignee must be a member of the project |
|
|
|
|
|
if not self.project.members.filter(id=self.assignee.id).exists(): |
|
|
|
|
|
raise ValidationError("Assignee must be a member of the project") |
|
|
|
|
|
|
|
|
|
|
|
# example must be in the project |
|
|
|
|
|
if not self.project.examples.filter(id=self.example.id).exists(): |
|
|
|
|
|
raise ValidationError("Example must be in the project") |
|
|
|
|
|
|
|
|
|
|
|
return super().clean() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleState(models.Model): |
|
|
class ExampleState(models.Model): |
|
|
objects = ExampleStateManager() |
|
|
objects = ExampleStateManager() |
|
|
example = models.ForeignKey(to=Example, on_delete=models.CASCADE, related_name="states") |
|
|
example = models.ForeignKey(to=Example, on_delete=models.CASCADE, related_name="states") |
|
|