diff --git a/dashboard/models.py b/dashboard/models.py index 64c20d9..482593c 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -143,28 +143,35 @@ def create_user_profile(sender, instance, created, **kwargs): profile.user = instance profile.save() +NEWMEDIA_STATUS_CHOICES = ( + ('1', '开启'), + ('0', '关闭') +) -# 微信公众号 -class Weixin(models.Model): - WEIXIN_STATUS_CHOICES = ( - ('1', '开启'), - ('0', '关闭') - ) +class NewMedia(models.Model): id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) code = models.CharField('微信公众号', max_length=256, null=True, blank=True) - weixinid = models.CharField('微信ID', max_length=256, null=True, blank=True) alias = models.CharField('别名', max_length=256, null=True, blank=True) image = models.FileField( upload_to='cover/%Y/%m/%d/', null=True, blank=True) organization = models.ForeignKey( Organization, on_delete=models.CASCADE, null=True, blank=True) status = models.CharField( - '状态', max_length=256, null=True, blank=True, choices=WEIXIN_STATUS_CHOICES) + '状态', max_length=256, null=True, blank=True, choices=NEWMEDIA_STATUS_CHOICES) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) + class Meta: + abstract = True + ordering = ["-created"] + def __str__(self): - return self.code + return self.code + ':' + self.alias + +# 微信公众号 +class Weixin(NewMedia): + weixinid = models.CharField('微信ID', max_length=256, null=True, blank=True) + # 微信文章采集 @@ -220,26 +227,8 @@ class Weixin_Wrong(models.Model): # 微博 -class Weibo(models.Model): - WEIBO_STATUS_CHOICES = ( - ('1', '开启'), - ('0', '关闭') - ) - id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) - code = models.CharField('微博号', max_length=256, null=True, blank=True) +class Weibo(NewMedia): weiboid = models.CharField('微博ID', max_length=256, null=True, blank=True) - alias = models.CharField('别名', max_length=256, null=True, blank=True) - image = models.FileField( - upload_to='cover/%Y/%m/%d/', null=True, blank=True) - organization = models.ForeignKey( - Organization, on_delete=models.CASCADE, null=True, blank=True) - status = models.CharField( - '状态', max_length=256, null=True, blank=True, choices=WEIBO_STATUS_CHOICES) - created = models.DateTimeField('创建时间', auto_now_add=True) - updated = models.DateTimeField('更新时间', auto_now=True) - - def __str__(self): - return self.code # 微博文章采集 @@ -284,25 +273,7 @@ class Weibo_Wrong(models.Model): # 今日头条 class Toutiao(models.Model): - TOUTIAO_STATUS_CHOICES = ( - ('1', '开启'), - ('0', '关闭') - ) - id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) - code = models.CharField('头条号', max_length=256, null=True, blank=True) toutiaoid = models.CharField('头条ID', max_length=256, null=True, blank=True) - alias = models.CharField('别名', max_length=256, null=True, blank=True) - image = models.FileField( - upload_to='cover/%Y/%m/%d/', null=True, blank=True) - organization = models.ForeignKey( - Organization, on_delete=models.CASCADE, null=True, blank=True) - status = models.CharField( - '状态', max_length=256, null=True, blank=True, choices=TOUTIAO_STATUS_CHOICES) - created = models.DateTimeField('创建时间', auto_now_add=True) - updated = models.DateTimeField('更新时间', auto_now=True) - - def __str__(self): - return self.code # 今日头条数据 @@ -360,23 +331,9 @@ class Toutiao_Wrong(models.Model): # 其他新媒体 class Qita(models.Model): - QITA_STATUS_CHOICES = ( - ('1', '开启'), - ('0', '关闭') - ) - id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) type = models.CharField('新媒体类型', max_length=256, null=True, blank=True) name = models.CharField('新媒体名称', max_length=256, null=True, blank=True) qitaid = models.CharField('新媒体ID', max_length=256, null=True, blank=True) - alias = models.CharField('别名', max_length=256, null=True, blank=True) - image = models.FileField( - upload_to='cover/%Y/%m/%d/', null=True, blank=True) - organization = models.ForeignKey( - Organization, on_delete=models.CASCADE, null=True, blank=True) - status = models.CharField( - '状态', max_length=256, null=True, blank=True, choices=QITA_STATUS_CHOICES) - created = models.DateTimeField('创建时间', auto_now_add=True) - updated = models.DateTimeField('更新时间', auto_now=True) def __str__(self): return self.name