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.
59 lines
2.2 KiB
59 lines
2.2 KiB
from django.db import models
|
|
from core.models import BaseModel
|
|
from crawler.models import CrawlTask
|
|
|
|
class Ad(BaseModel):
|
|
divar_token = models.CharField(max_length=50, unique=True)
|
|
title = models.CharField(max_length=255)
|
|
description = models.TextField()
|
|
price = models.CharField(max_length=100, null=True, blank=True)
|
|
category = models.CharField(max_length=100, null=True, blank=True)
|
|
images = models.JSONField(default=list)
|
|
url = models.URLField()
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
published_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
class Meta:
|
|
indexes = [
|
|
models.Index(fields=['created_at']),
|
|
]
|
|
|
|
def __str__(self):
|
|
return f"{self.title} (Token: {self.divar_token})"
|
|
|
|
|
|
class AdEvaluation(BaseModel):
|
|
crawl_task = models.ForeignKey(CrawlTask, on_delete=models.CASCADE, related_name='evaluations')
|
|
ad = models.ForeignKey(Ad, on_delete=models.PROTECT, related_name='evaluations')
|
|
is_flagged = models.BooleanField(default=False)
|
|
reason = models.TextField(null=True, blank=True)
|
|
confidence = models.FloatField(null=True, blank=True)
|
|
extracted_fields = models.JSONField(default=dict)
|
|
evaluated_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
constraints = [
|
|
models.UniqueConstraint(fields=['crawl_task', 'ad'], name='unique_crawl_task_ad')
|
|
]
|
|
indexes = [
|
|
models.Index(fields=['is_flagged']),
|
|
models.Index(fields=['evaluated_at']),
|
|
]
|
|
|
|
def __str__(self):
|
|
return f"Evaluation of Ad {self.ad.id} under Task {self.crawl_task.title} (Flagged: {self.is_flagged})"
|
|
|
|
class NotificationLog(BaseModel):
|
|
STATUS_CHOICES = [
|
|
('SENT', 'Sent'),
|
|
('FAILED', 'Failed'),
|
|
]
|
|
|
|
evaluation = models.ForeignKey(AdEvaluation, on_delete=models.CASCADE, related_name='notifications')
|
|
channel_id = models.CharField(max_length=100)
|
|
sent_at = models.DateTimeField(auto_now_add=True)
|
|
status = models.CharField(max_length=20, choices=STATUS_CHOICES)
|
|
error_message = models.TextField(null=True, blank=True)
|
|
|
|
def __str__(self):
|
|
return f"Notification to {self.channel_id} (Status: {self.status})"
|