models.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from django.db import models
  2. class AttributeMaster(models.Model):
  3. name = models.CharField(max_length=100, unique=True) # e.g., "Brand", "Capacity"
  4. is_mandatory = models.BooleanField(default=False)
  5. def __str__(self):
  6. return self.name
  7. class TitleMapping(models.Model):
  8. product_type = models.CharField(max_length=255, unique=True) # e.g., "Flammable Safety Cabinet-Links"
  9. # Store sequence as a comma-separated string: "Brand,Product Type,Door Type,Capacity,Dimensions,Color"
  10. format_sequence = models.TextField()
  11. def get_sequence_list(self):
  12. return [item.strip() for item in self.format_sequence.split(',') if item.strip()]
  13. def __str__(self):
  14. return self.product_type
  15. class ProcessingTask(models.Model):
  16. task_id = models.CharField(max_length=100, unique=True)
  17. original_filename = models.CharField(max_length=255, null=True, blank=True) # New field
  18. status = models.CharField(max_length=20, default='PENDING')
  19. download_url = models.TextField(null=True, blank=True)
  20. created_at = models.DateTimeField(auto_now_add=True)
  21. completed_at = models.DateTimeField(null=True, blank=True)
  22. def __str__(self):
  23. return f"{self.original_filename} - {self.status}"
  24. @property
  25. def duration(self):
  26. """Calculates how long the process took."""
  27. if self.completed_at and self.created_at:
  28. return self.completed_at - self.created_at
  29. return None