You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import uuid
  2. from django.contrib.auth.models import User
  3. from django.db import models
  4. from django_drf_filepond.models import DrfFilePondStoredStorage
  5. from .managers import ExampleManager, ExampleStateManager
  6. from projects.models import Project
  7. class Example(models.Model):
  8. objects = ExampleManager()
  9. uuid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True, unique=True)
  10. meta = models.JSONField(default=dict)
  11. filename = models.FileField(default=".", max_length=1024, storage=DrfFilePondStoredStorage())
  12. upload_name = models.CharField(max_length=512)
  13. project = models.ForeignKey(to=Project, on_delete=models.CASCADE, related_name="examples")
  14. annotations_approved_by = models.ForeignKey(to=User, on_delete=models.SET_NULL, null=True, blank=True)
  15. text = models.TextField(null=True, blank=True)
  16. score = models.FloatField(default=100)
  17. created_at = models.DateTimeField(auto_now_add=True, db_index=True)
  18. updated_at = models.DateTimeField(auto_now=True)
  19. @property
  20. def comment_count(self):
  21. return Comment.objects.filter(example=self.id).count()
  22. @property
  23. def data(self):
  24. if self.project.is_text_project:
  25. return self.text
  26. else:
  27. return str(self.filename)
  28. class Meta:
  29. ordering = ["created_at"]
  30. class ExampleState(models.Model):
  31. objects = ExampleStateManager()
  32. example = models.ForeignKey(to=Example, on_delete=models.CASCADE, related_name="states")
  33. confirmed_by = models.ForeignKey(to=User, on_delete=models.CASCADE)
  34. confirmed_at = models.DateTimeField(auto_now=True)
  35. class Meta:
  36. unique_together = (("example", "confirmed_by"),)
  37. class Comment(models.Model):
  38. text = models.TextField()
  39. example = models.ForeignKey(to=Example, on_delete=models.CASCADE, related_name="comments")
  40. user = models.ForeignKey(to=User, on_delete=models.CASCADE, null=True)
  41. created_at = models.DateTimeField(auto_now_add=True, db_index=True)
  42. updated_at = models.DateTimeField(auto_now=True)
  43. @property
  44. def username(self):
  45. return self.user.username
  46. class Meta:
  47. ordering = ["created_at"]