56 lines
2.3 KiB
Python
56 lines
2.3 KiB
Python
|
from django.db import models
|
|||
|
|
|||
|
# Create your models here.
|
|||
|
from django.db import models
|
|||
|
|
|||
|
class Task(models.Model):
|
|||
|
TASK_STATUS_CHOICES = [
|
|||
|
('running', '进行中'),
|
|||
|
('idle', '空闲中'),
|
|||
|
('done', '完成'),
|
|||
|
('failed', '失败'),
|
|||
|
]
|
|||
|
|
|||
|
EXECUTION_TYPE_CHOICES = [
|
|||
|
('scheduled', '定期执行'),
|
|||
|
('predefined', '预定时间执行'),
|
|||
|
]
|
|||
|
|
|||
|
task_id = models.CharField(max_length=64, unique=True)
|
|||
|
name = models.CharField(max_length=200)
|
|||
|
description = models.TextField(blank=True, null=True)
|
|||
|
last_run_date = models.DateField(null=True, blank=True)
|
|||
|
execution_type = models.CharField(
|
|||
|
max_length=20,
|
|||
|
choices=EXECUTION_TYPE_CHOICES,
|
|||
|
blank=True,
|
|||
|
null=True
|
|||
|
)
|
|||
|
# 一次性执行使用 DateTimeField
|
|||
|
execution_time = models.DateTimeField(blank=True, null=True)
|
|||
|
# 每天执行使用 TimeField
|
|||
|
scheduled_time = models.CharField(max_length=10, blank=True, null=True) # 改为字符串 HH:MM
|
|||
|
parse_flag = models.BooleanField(default=False)
|
|||
|
limit = models.IntegerField(default=60) # ⭐ 新增的字段,默认60
|
|||
|
status = models.CharField(max_length=20, choices=TASK_STATUS_CHOICES, default='idle')
|
|||
|
created_at = models.DateTimeField(auto_now_add=True)
|
|||
|
updated_at = models.DateTimeField(auto_now=True)
|
|||
|
|
|||
|
def __str__(self):
|
|||
|
return self.name
|
|||
|
class TaskDetail(models.Model):
|
|||
|
task = models.ForeignKey(Task, related_name="details", on_delete=models.CASCADE)
|
|||
|
author = models.CharField(max_length=500, blank=True)
|
|||
|
date = models.CharField(max_length=100, blank=True, null=True) # 改为字符串
|
|||
|
download = models.IntegerField(blank=True, null=True)
|
|||
|
keywords = models.TextField(blank=True) # 存储 ; 分隔的关键字
|
|||
|
original_link = models.URLField(blank=True)
|
|||
|
pdf_url = models.URLField(blank=True)
|
|||
|
quote = models.TextField(blank=True)
|
|||
|
source = models.CharField(max_length=200, blank=True)
|
|||
|
site = models.CharField(max_length=200, blank=True)
|
|||
|
summary = models.TextField(blank=True)
|
|||
|
parsed_summary = models.JSONField(blank=True, null=True) # 存储 JSON
|
|||
|
title = models.CharField(max_length=300, blank=True)
|
|||
|
created_at = models.DateTimeField(auto_now_add=True)
|