from django.contrib import admin
from django.urls import path,include
#導兩個包
from django.views.static import serve
from andun import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('myapp.urls')),
path('upload/<path>',serve,{'document_root':settings.UPLOAD_FILE})
]
app下的urls.py
from rest_framework.routers import DefaultRouter
from myapp import views
router = DefaultRouter()
router.register('',views.HelloWorldViewSet,basename='hello')
urlpatterns = router.urls
app下的views.py
from email import header
from lib2to3.pgen2 import driver
from django.db.models import Q, query
from requests import head
from myapp import models
from rest_framework.viewsets import GenericViewSet
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import pagination #分頁
import datetime
import os
from andun import settings
import re
import requests
from selenium import webdriver
import time
# Create your views here.
#初始化驅動
driver=webdriver.Chrome()
driver.minimize_window()
class HelloWorldViewSet(GenericViewSet):
@action(detail=False,methods=['GET'])
def get_code(self,request):
return Response({'code':'200'})
@action(detail=False,methods=['POST'])
def login(self,request):
'''操作登陸後的頁面'''
code=request.data.get('code')
return Response({'code':'200'})
app下的models.py
from django.db import models
from django.db.models.deletion import CASCADE
from django.db.models.fields import Field
# Create your models here.
class User(models.Model):
'''用戶表'''
name=models.CharField(verbose_name='用戶名字',max_length=50,primary_key=True,db_index=True)
tag=models.CharField(verbose_name='標簽',max_length=50,db_index=True,default='')
create_time=models.CharField(verbose_name='創建時間戳',max_length=50,default=0)
class Meta:
managed=True
verbose_name_plural='用戶表'
def __str__(self):
return self.name
class Group(models.Model):
'''群聊表'''
send=models.ForeignKey(User,on_delete=CASCADE)
recive=models.CharField(verbose_name='接收方',max_length=50)
group_id=models.IntegerField(verbose_name='群聊編號')
msgtime=models.IntegerField(verbose_name='發送時間')
msgtype=models.CharField(verbose_name='消息類型',max_length=50)
msg=models.CharField(verbose_name='消息內容',max_length=2550)
class Meta:
managed=True
verbose_name_plural='群聊表'
def __str__(self):
return self.send.name
class Alone(models.Model):
'''獨聊表'''
send=models.ForeignKey(User,on_delete=CASCADE)
recive=models.CharField(verbose_name='接收方',max_length=50)
msgtime=models.IntegerField(verbose_name='發送時間')
msgtype=models.CharField(verbose_name='消息類型',max_length=50)
msg=models.CharField(verbose_name='消息內容',max_length=2550)
class Meta:
managed=True
verbose_name_plural='獨聊表'
def __str__(self):
return self.send.name
class File(models.Model):
'''文件表'''
user=models.ForeignKey(User,on_delete=CASCADE)
file_path=models.CharField(verbose_name='文件路徑',max_length=500)
file_classify=models.CharField(verbose_name='文件類型',max_length=50)
class Meta:
managed=True
verbose_name_plural='文件表'
def __str__(self):
return self.user.name
class Identity(models.Model):
'''身份表'''
identity=models.CharField(verbose_name='身份',max_length=30,primary_key=True,db_index=True)
class Meta:
managed=True
verbose_name_plural='身份表'
def __str__(self):
return self.identity
class Account(models.Model):
'''賬號表'''
account=models.CharField(verbose_name='賬號',max_length=20,primary_key=True,db_index=True)
password=models.CharField(verbose_name='密碼',max_length=20)
identity_id=models.ForeignKey(Identity,on_delete=CASCADE)
class Meta:
managed=True
verbose_name_plural='賬號表'
def __str__(self):
return self.account
class File_Privilege(models.Model):
'''文件權限表'''
file_path=models.CharField(verbose_name='文件路徑',max_length=500,primary_key=True)
user=models.ForeignKey(User,on_delete=CASCADE)
file_classify=models.CharField(verbose_name='文件類型',max_length=50)
name=models.CharField(verbose_name='文件名',max_length=500)
file_grade=models.IntegerField(verbose_name='文件層級',default=1)
last_file=models.CharField(verbose_name='上一級文件目錄',max_length=500,default='')
is_folder=models.BooleanField(verbose_name='是否為文件夾',default=False)
class Meta:
managed=True
verbose_name_plural='文件權限表'
def __str__(self):
return self.file_path
class Account_File_Privilege(models.Model):
'''帳號文件權限表'''
file_path=models.ForeignKey(File_Privilege,on_delete=CASCADE)
account=models.ForeignKey(Account,on_delete=CASCADE)
add=models.BooleanField(verbose_name='是否可以增加文件',default=False)
rm=models.BooleanField(verbose_name='是否可以刪除文件',default=False)
edit=models.BooleanField(verbose_name='是否可以編輯文件',default=False)
class Meta:
managed=True
verbose_name_plural='賬號文件權限表'
def __str__(self):
return self.file_path.file_path+'——>'+self.account.account
class Account_Navigation_Privilege(models.Model):
'''賬號導航欄權限表'''
name=models.CharField(verbose_name='導航名',max_length=500)
account=models.ForeignKey(Account,on_delete=CASCADE)
class Meta:
managed=True
verbose_name_plural='賬號導航欄權限表'
def __str__(self):
return self.name+'——>'+self.account.account
class Identity_File_Privilege(models.Model):
'''身份文件權限表'''
file_path=models.ForeignKey(File_Privilege,on_delete=CASCADE)
identity_id=models.ForeignKey(Identity,on_delete=CASCADE)
add=models.BooleanField(verbose_name='是否可以增加文件',default=False)
rm=models.BooleanField(verbose_name='是否可以刪除文件',default=False)
edit=models.BooleanField(verbose_name='是否可以編輯文件',default=False)
class Meta:
managed=True
verbose_name_plural='身份文件權限表'
def __str__(self):
return self.file_path.file_path+'——>'+self.identity_id.identity
class Identity_Navigation_Privilege(models.Model):
'''身份導航欄權限表'''
name=models.CharField(verbose_name='導航名',max_length=500)
identity_id=models.ForeignKey(Identity,on_delete=CASCADE)
class Meta:
managed=True
verbose_name_plural='身份導航欄權限表'
def __str__(self):
return self.name+'——>'+self.identity_id.identity
class Food_File(models.Model):
'''文件上傳食物路徑表'''
file_path=models.CharField(verbose_name='服務器路徑',max_length=500)
file_truth=models.CharField(verbose_name='本地路徑',max_length=500,default='')
handle_res=models.BooleanField(verbose_name='是否通過',default=False)
is_handle=models.BooleanField(verbose_name='是否處理',default=False)
class Meta:
managed=True
verbose_name_plural='文件上傳食物路徑表'
def __str__(self):
return self.file_path