add media

This commit is contained in:
baoliang 2020-09-04 22:42:41 +08:00
parent 85a8b0f96e
commit fe8e63df7a
10 changed files with 153 additions and 68 deletions

View File

@ -4,35 +4,42 @@ from django.contrib.auth.models import User
from django.db import models
# 权限等级
class Level(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('等级名', max_length=256, null=True, blank=True)
level = models.IntegerField('级别', blank=True, null=True,default=0)
level = models.IntegerField('级别', blank=True, null=True, default=0)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.name
# Create your models here.
class Group_type(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
type = models.CharField('群组类型',max_length=256,null=True,blank=True)
type = models.CharField('群组类型', max_length=256, null=True, blank=True)
def __str__(self):
return self.type
# 群组
class Group(models.Model):
GROUP_STATUS_CHOICES = (
('0','关闭'),
('1','开启')
('0', '关闭'),
('1', '开启')
)
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('群组名称', max_length=256, null=True, blank=True)
presentation = models.TextField('群组描述', null=True, blank=True)
image = models.FileField(upload_to='groupimage', null=True, blank=True)
type = models.ForeignKey(Group_type,on_delete=models.CASCADE,null=True,blank=True)
status = models.CharField('状态',max_length=256,null=True,blank=True,choices=GROUP_STATUS_CHOICES)
type = models.ForeignKey(
Group_type, on_delete=models.CASCADE, null=True, blank=True)
status = models.CharField(
'状态', max_length=256, null=True, blank=True, choices=GROUP_STATUS_CHOICES)
province = models.CharField('', max_length=256, null=True, blank=True)
cities = models.CharField('', max_length=256, null=True, blank=True)
district = models.CharField('', max_length=256, null=True, blank=True)
@ -45,31 +52,42 @@ class Group(models.Model):
def __str__(self):
return self.name
#群组管理员
# 群组管理员
class Group_admin(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(Group, on_delete=models.CASCADE, null=True, blank=True)
user = models.ForeignKey(
User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(
Group, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.group.name
#群组成员
# 群组成员
class Group_user(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(Group, on_delete=models.CASCADE, null=True, blank=True)
user = models.ForeignKey(
User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey(
Group, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
def __str__(self):
return self.user.username
#单位类型
# 单位类型
class Organizationtype(models.Model):
id = models.UUIDField('id',primary_key=True,default=uuid.uuid4)
organizationtype = models.CharField('单位类型',blank=True,null=True,max_length=256)
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
organizationtype = models.CharField(
'单位类型', blank=True, null=True, max_length=256)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -82,12 +100,13 @@ class Organization(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
name = models.CharField('单位名', max_length=256, null=True, blank=True)
image = models.FileField(upload_to='cover', null=True, blank=True)
organizationtype = models.ForeignKey(Organizationtype,on_delete=models.CASCADE, null=True, blank=True)
province = models.CharField('',max_length=256,null=True,blank=True)
cities = models.CharField('',max_length=256,null=True,blank=True)
district = models.CharField('',max_length=256,null=True,blank=True)
town = models.CharField('',max_length=256,null=True,blank=True)
village = models.CharField('',max_length=256,null=True,blank=True)
organizationtype = models.ForeignKey(
Organizationtype, on_delete=models.CASCADE, null=True, blank=True)
province = models.CharField('', max_length=256, null=True, blank=True)
cities = models.CharField('', max_length=256, null=True, blank=True)
district = models.CharField('', max_length=256, null=True, blank=True)
town = models.CharField('', max_length=256, null=True, blank=True)
village = models.CharField('', max_length=256, null=True, blank=True)
# group = models.ForeignKey(Group, on_delete=models.CASCADE, null=True, blank=True)
# level = models.ForeignKey(Level,on_delete=models.CASCADE,null=True,blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
@ -103,9 +122,10 @@ class Userprofile(models.Model):
name = models.CharField('姓名', null=True, blank=True, max_length=256)
sex = models.CharField('性别', null=True, blank=True, max_length=256)
image = models.FileField(upload_to='profile', null=True, blank=True)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True)
#用户状态:注册进来默认为0为未审核状态审核后status=1
status = models.IntegerField('用户状态',null=True,blank=True,default=0)
organization = models.ForeignKey(
Organization, on_delete=models.CASCADE, null=True, blank=True)
# 用户状态:注册进来默认为0为未审核状态审核后status=1
status = models.IntegerField('用户状态', null=True, blank=True, default=0)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -113,7 +133,7 @@ class Userprofile(models.Model):
ordering = ["-created"]
def __str__(self):
return self.user.username
return self.user.username+":"+self.name
def create_user_profile(sender, instance, created, **kwargs):
@ -132,11 +152,14 @@ class Weixin(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)
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)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -156,7 +179,8 @@ class Weixin_data(models.Model):
comment = models.CharField('评论数', max_length=256, null=True, blank=True)
reply = models.CharField('作者回复数', max_length=256, null=True, blank=True)
content = models.TextField('正文', null=True, blank=True)
weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE, null=True, blank=True)
weixin = models.ForeignKey(
Weixin, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -170,7 +194,8 @@ class Weixin_comment(models.Model):
comment = models.TextField('评论', null=True, blank=True)
user = models.CharField('用户', max_length=256, null=True, blank=True)
reply = models.TextField('回复', null=True, blank=True)
weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE, null=True, blank=True)
weixin = models.ForeignKey(
Weixin, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -184,7 +209,8 @@ class Weixin_Wrong(models.Model):
wrong = models.CharField('错别字', max_length=256, null=True, blank=True)
idea = models.CharField('建议', max_length=256, null=True, blank=True)
site = models.CharField('位置', max_length=256, null=True, blank=True)
weixin = models.ForeignKey(Weixin, on_delete=models.CASCADE, null=True, blank=True)
weixin = models.ForeignKey(
Weixin, on_delete=models.CASCADE, null=True, blank=True)
change = models.BooleanField('是否已修改', null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -203,9 +229,12 @@ class Weibo(models.Model):
code = models.CharField('微博号', max_length=256, null=True, blank=True)
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)
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)
@ -219,8 +248,10 @@ class Weibo_data(models.Model):
weiboid = models.CharField('微博ID', max_length=256, null=True, blank=True)
content = models.TextField('正文', null=True, blank=True)
url = models.CharField('文章url', max_length=256, null=True, blank=True)
originalimageurl = models.CharField('原始图片url', max_length=256, null=True, blank=True)
transpondimageurl = models.CharField('转发图片url', max_length=256, null=True, blank=True)
originalimageurl = models.CharField(
'原始图片url', max_length=256, null=True, blank=True)
transpondimageurl = models.CharField(
'转发图片url', max_length=256, null=True, blank=True)
original = models.BooleanField('是否原创', null=True, blank=True)
site = models.CharField('发布位置', max_length=256, null=True, blank=True)
date = models.CharField('发布时间', max_length=256, null=True, blank=True)
@ -229,7 +260,8 @@ class Weibo_data(models.Model):
transpond = models.CharField('转发数', max_length=256, null=True, blank=True)
comment = models.CharField('评论数', max_length=256, null=True, blank=True)
title = models.CharField('文章标题', max_length=256, null=True, blank=True)
weibo = models.ForeignKey(Weibo, on_delete=models.CASCADE, null=True, blank=True)
weibo = models.ForeignKey(
Weibo, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -243,7 +275,8 @@ class Weibo_Wrong(models.Model):
wrong = models.CharField('错别字', max_length=256, null=True, blank=True)
idea = models.CharField('建议', max_length=256, null=True, blank=True)
site = models.CharField('位置', max_length=256, null=True, blank=True)
weibo = models.ForeignKey(Weibo, on_delete=models.CASCADE, null=True, blank=True)
weibo = models.ForeignKey(
Weibo, on_delete=models.CASCADE, null=True, blank=True)
change = models.BooleanField('是否已修改', null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -259,9 +292,12 @@ class Toutiao(models.Model):
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)
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)
@ -276,12 +312,14 @@ class Toutiao_data(models.Model):
url = models.CharField('链接', max_length=256, null=True, blank=True)
img = models.CharField('缩略图', max_length=256, null=True, blank=True)
count = models.CharField('阅读数', max_length=256, null=True, blank=True)
commentcount = models.CharField('评论数', max_length=256, null=True, blank=True)
commentcount = models.CharField(
'评论数', max_length=256, null=True, blank=True)
reply = models.CharField('作者回复数', max_length=256, null=True, blank=True)
date = models.CharField('时间', max_length=256, null=True, blank=True)
content = models.TextField('正文', null=True, blank=True)
comment = models.TextField('评论', null=True, blank=True)
toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE, null=True, blank=True)
toutiao = models.ForeignKey(
Toutiao, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -295,7 +333,8 @@ class Toutiao_comment(models.Model):
comment = models.TextField('评论', null=True, blank=True)
user = models.CharField('用户', max_length=256, null=True, blank=True)
reply = models.TextField('回复', null=True, blank=True)
toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE, null=True, blank=True)
toutiao = models.ForeignKey(
Toutiao, on_delete=models.CASCADE, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -309,7 +348,8 @@ class Toutiao_Wrong(models.Model):
wrong = models.CharField('错别字', max_length=256, null=True, blank=True)
idea = models.CharField('建议', max_length=256, null=True, blank=True)
site = models.CharField('位置', max_length=256, null=True, blank=True)
toutiao = models.ForeignKey(Toutiao, on_delete=models.CASCADE, null=True, blank=True)
toutiao = models.ForeignKey(
Toutiao, on_delete=models.CASCADE, null=True, blank=True)
change = models.BooleanField('是否已修改', null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True)
@ -329,21 +369,27 @@ class Qita(models.Model):
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)
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
#其他新媒体监测
# 其他新媒体监测
class Qita_jc(models.Model):
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
mewnedia = models.ForeignKey(Qita,on_delete=models.CASCADE)
mewnedia = models.ForeignKey(Qita, on_delete=models.CASCADE)
count = models.CharField('总发文量', max_length=256, null=True, blank=True)
count_jc = models.CharField('监测时间内发文量', max_length=256, null=True, blank=True)
count_jc = models.CharField(
'监测时间内发文量', max_length=256, null=True, blank=True)
comment = models.CharField('评论数', max_length=256, null=True, blank=True)
reply = models.CharField('作者回复数', max_length=256, null=True, blank=True)
date = models.CharField('最近发文日期', max_length=256, null=True, blank=True)
@ -352,12 +398,15 @@ class Qita_jc(models.Model):
def __str__(self):
return self.mewnedia.name
#5级地名库
# 5级地名库
class Area_code_2020(models.Model):
code = models.CharField('区划代码',max_length=256,null=True,blank=True)
name = models.CharField('名称',max_length=256,null=True,blank=True)
level = models.CharField('级别1-5,省市县镇村',max_length=256,null=True,blank=True)
pcode = models.CharField('父级区划代码',max_length=256,null=True,blank=True)
code = models.CharField('区划代码', max_length=256, null=True, blank=True)
name = models.CharField('名称', max_length=256, null=True, blank=True)
level = models.CharField(
'级别1-5,省市县镇村', max_length=256, null=True, blank=True)
pcode = models.CharField('父级区划代码', max_length=256, null=True, blank=True)
def __str__(self):
return self.name

Binary file not shown.

After

Width:  |  Height:  |  Size: 783 KiB

View File

@ -1,9 +1,10 @@
from django.http import HttpResponse
def polls_login_required(function):
def wrapper(request, *args, **kwargs):
u = request.user
if not request.user.is_authenticated:
if not u.is_authenticated:
return HttpResponse(status=401)
else:
return function(request, *args, **kwargs)

View File

@ -15,4 +15,5 @@ urlpatterns = [
path('notices/list/', views.notices, name='polls_notices'),
path('notices/read/', views.read_notice, name='polls_read_notice'),
path('medias/create/', views.create_media, name='polls_add_media'),
path('medias/list/', views.medias, name='polls_medias')
]

View File

@ -1,3 +1,3 @@
from .user import index, status_500, status_401, polls_login, send_code, register_step_one, register_step_two, password_recover_step_one, password_recover_step_two
from .notice import notices, read_notice
from .media import create_media
from .media import medias, create_media

View File

@ -1,9 +1,44 @@
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.core.paginator import Paginator
from dashboard.models import Weixin, Weibo, Toutiao, Qita
from polls.decorators import polls_login_required
@csrf_exempt
@polls_login_required
def medias(request):
if request.method == 'POST':
return HttpResponse(status=405)
category = request.POST.get('category', 'weixin')
if category == 'weixin':
q = Weixin.objects.filter(status=1)
elif category == 'weibo':
q = Weibo.objects.filter(status=1)
elif category == 'toutiao':
q = Toutiao.objects.filter(status=1)
else:
q = Qita.objects.filter(status=1)
results = []
for o in q:
result = dict()
result['id'] = o.id
result['code'] = o.code
if category == 'weixin':
result['media_id'] = o.weixinid
elif category == 'weibo':
result['media_id'] = o.weixinid
elif category == 'toutiao':
result['media_id'] = o.weixinid
else:
result['media_id'] = o.weixinid
result['alias'] = o.alias
result['thumbnail'] = request.build_absolute_uri(o.image.url)
results.append(result)
return JsonResponse(results, safe=False)
@csrf_exempt
@polls_login_required
def create_media(request):

View File

@ -46,7 +46,6 @@ def polls_login(request):
if profile:
result['name'] = profile.name
result['gender'] = profile.sex
result['thumbnail'] = profile.image.path
result['organization'] = profile.organization.name
return JsonResponse({'status': 'success', 'message': result})
else: