# Django models.py
from django.db import models
from django.utils import timezone
from myapp.models.model_account import User
class SpiderTask(models.Model):
"""爬虫任务表"""
PLATFORM_CHOICES = (
(1, 'Amazon'),
(2, 'Etsy'),
(3, 'Temu'),
(4, 'WalMart')
)
STATUS_CHOICES = (
(0, '进行中'),
(1, '已完成'),
(2, '异常'),
)
TYPE_CHOICES = (
(1, '列表页'),
(2, '详情页'),
)
id = models.AutoField(primary_key=True, verbose_name='自增id')
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
platform = models.IntegerField(default=1, choices=PLATFORM_CHOICES, verbose_name='平台')
name = models.CharField(verbose_name="爬虫名称", max_length=255)
start_url = models.URLField(verbose_name="起始url", max_length=500, null=False)
spider_type = models.IntegerField(choices=TYPE_CHOICES, default=1, verbose_name='采集页面类型')
description = models.TextField(verbose_name="描述备注等", max_length=500, null=True, blank=True)
completed = models.IntegerField(choices=STATUS_CHOICES, default=0, verbose_name='完成状态')
created_at = models.DateTimeField(default=timezone.now, verbose_name='加入任务时间')
collection_status = models.IntegerField(choices=STATUS_CHOICES, default=0, verbose_name='采集状态')
completed_at = models.DateTimeField(null=True, blank=True, verbose_name='完成时间')
products = models.ManyToManyField('SpiderProduct', verbose_name='关联商品', related_name='tasks')
class Meta:
verbose_name = '爬虫任务'
verbose_name_plural = '爬虫任务'
unique_together = [['user', 'start_url']]
def __str__(self):
return f"{self.platform} - {self.name}"
class SpiderProduct(models.Model):
"""爬虫结果表"""
# 省略字段定义...
class Meta:
verbose_name = '爬虫结果'
verbose_name_plural = '爬虫结果'
def __str__(self):
return self.title
评论