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.

32 lines
1.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. from auto_labeling_pipeline.models import RequestModelFactory
  2. from django.core.exceptions import ValidationError
  3. from django.db import models
  4. from projects.models import Project
  5. class AutoLabelingConfig(models.Model):
  6. TASK_CHOICES = (("Category", "category"), ("Span", "span"), ("Text", "text"), ("Relation", "relation"))
  7. model_name = models.CharField(max_length=100)
  8. model_attrs = models.JSONField(default=dict)
  9. template = models.TextField(default="")
  10. label_mapping = models.JSONField(default=dict, blank=True)
  11. project = models.ForeignKey(to=Project, on_delete=models.CASCADE, related_name="auto_labeling_config")
  12. task_type = models.CharField(max_length=100, choices=TASK_CHOICES)
  13. default = models.BooleanField(default=False)
  14. created_at = models.DateTimeField(auto_now_add=True)
  15. updated_at = models.DateTimeField(auto_now=True)
  16. def __str__(self):
  17. return self.model_name
  18. def clean_fields(self, exclude=None):
  19. super().clean_fields(exclude=exclude)
  20. try:
  21. RequestModelFactory.find(self.model_name)
  22. except NameError:
  23. message = f"The specified model name {self.model_name} does not exist."
  24. raise ValidationError(message)
  25. except Exception:
  26. message = "The attributes does not match the model."
  27. raise ValidationError(message)