12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- # models.py
- from django.db import models
- from django.contrib.postgres.fields import JSONField
- import json
- class Product(models.Model):
- """Product model to store basic product information"""
- sku = models.CharField(max_length=100, unique=True)
- category = models.CharField(max_length=100)
- title = models.TextField()
- description = models.TextField(blank=True)
- attributes = models.JSONField(default=dict)
- created_at = models.DateTimeField(auto_now_add=True)
- updated_at = models.DateTimeField(auto_now=True)
-
- class Meta:
- indexes = [
- models.Index(fields=['category']),
- models.Index(fields=['sku']),
- ]
-
- def __str__(self):
- return f"{self.sku} - {self.title}"
- class AttributeScore(models.Model):
- """Store attribute quality scores"""
- product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='attribute_scores')
- score = models.FloatField()
- max_score = models.FloatField(default=100.0)
- details = models.JSONField(default=dict)
- issues = models.JSONField(default=list)
- suggestions = models.JSONField(default=list)
- ai_suggestions = models.JSONField(default=dict, blank=True) # Gemini AI suggestions
- processing_time = models.FloatField(null=True, blank=True)
- created_at = models.DateTimeField(auto_now_add=True)
-
- class Meta:
- indexes = [
- models.Index(fields=['-created_at']),
- ]
-
- def __str__(self):
- return f"{self.product.sku} - Score: {self.score}/{self.max_score}"
- class CategoryAttributeRule(models.Model):
- """Define mandatory attributes per category"""
- category = models.CharField(max_length=100)
- attribute_name = models.CharField(max_length=100)
- is_mandatory = models.BooleanField(default=False)
- valid_values = models.JSONField(default=list, blank=True)
- data_type = models.CharField(max_length=50, default='string')
- validation_regex = models.CharField(max_length=500, blank=True)
- min_length = models.IntegerField(null=True, blank=True)
- max_length = models.IntegerField(null=True, blank=True)
- description = models.TextField(blank=True)
-
- class Meta:
- unique_together = ('category', 'attribute_name')
- indexes = [
- models.Index(fields=['category']),
- ]
-
- def __str__(self):
- return f"{self.category} - {self.attribute_name}"
|