发布时间:2023-04-13 12:00
本系统一共分为前台系统功能和后台系统功能两个模块,两个模块之间虽然在表面上是相互独立的,但是在对数据库的访问上是紧密相连的,各个模块访在同一数据库中分别对应不同的数据表。根据以上的功能分析,系统在前后台两个模块的基础上每一个模块又分为几个子模块。
一、前台系统功能模块设计
1、会员注册模块:填写并提交个人信息,通过验证成功注册成为会员;
2、会员登录模块:注册后进行会员登录,便于进行之后的购买商品操作;
3、电影推荐模块:通过热销电影、按影片类型分类,分区域和页面展示网站的热销、新品等,根据用户浏览记录进行电影推荐,基于协调推荐算法推荐;
4、会员购票模块:通过对电影信息的浏览,选出自己喜爱的电影并选择购买,随后可提交评价或在购物车中查看;
5、评价查询模块:用户通过查看评价了解自己当前评价信息及所有评价记录。
三、后台系统功能模块设计
1、用户管理模块:该模块可以对用户的信息进行修改和删除;
2、电影分类管理模块:电影分类模块下分为两个子模块,一是一级分类管理,是通过影片类型对电影进行分类,二是二级分类管理,是通过国家地区的不同对电影归类;
3、电影信息管理模块:该模块可实现对电影基本信息的添加、修改和删除;
4、评价管理模块:管理员查看评价详细信息,删除评价信息,并对评价进行处理。
from django.views.generic.base import View
from datetime import datetime
from django.shortcuts import render
from django.http import HttpResponse
from django.core.paginator import PageNotAnInteger,Paginator
from operation.models import UserFavorite,UserComments,UserBrowse,UserRatings
from movieinfo.models import Movie,MovieParticulars
class AddFavView(View):
“”“用户收藏和取消收藏”\"\"
def post(self,request):
# 防止后边int(fav_id)时出错
id=request.POST.get(‘fav_id’,0)
if not request.user.is_authenticated:
# 未登录时返回json提示未登录,跳转到登录页面是在ajax中做
return HttpResponse(’{“status”:“fail”,“msg”:“用户未登录”}’, content_type=‘application/json’)
exist_record=UserFavorite.objects.filter(user=request.user, movie_id=int(id))
if exist_record:
# 如果记录已经存在,表示用户要取消收藏
exist_record.delete()
movie=Movie.objects.get(id=int(id))
movie.fav_nums -= 1
if movie.fav_nums < 0:
movie.fav_nums = 0
movie.save()
return HttpResponse(’{“status”:“success”,“msg”:“收藏”}’, content_type=‘application/json’)
else:
user_fav=UserFavorite()
if int(id) > 0:
user_fav.movie_id=int(id)
user_fav.user=request.user
user_fav.save()
movie = Movie.objects.get(id=int(id))
movie.fav_nums += 1
movie.save()
return HttpResponse(’{“status”:“success”,“msg”:“已收藏”}’, content_type=‘application/json’)
else:
return HttpResponse(’{“status”:“success”,“msg”:“收藏出错”}’, content_type=‘application/json’)
class AddCommentsView(View):
def post(self, request):
if not request.user.is_authenticated:
return HttpResponse(’{“status”:“fail”, “msg”:“用户未登录”}’, content_type=‘application/json’)
movie_id = request.POST.get(‘movie_id’, 0)
comments = request.POST.get(‘comments’, ‘’)
if int(movie_id)> 0 and comments:
movie_comments = UserComments() # 实例化
movie = Movie.objects.get(id= int(movie_id))
movie_comments.movie = movie
movie_comments.user = request.user
movie_comments.comment = comments
movie_comments.save()
# return render(request,‘playMovie.html’,{“status”:“success”, “msg”:“评论成功”,“movie_comments”: movie_comments})
return HttpResponse(’{“status”:“success”, “msg”:“评论成功”}’, content_type=‘application/json’)
else:
return HttpResponse(’{“status”:“fail”, “msg”:“评论失败”}’, content_type=‘application/json’)
class MovieDetailView(View):
# 电影详情页
def get(self, request, movie_id):
movieId=Movie.objects.get(id= int(movie_id))
# 点击数加一
movieId.click_nums += 1
movieId.save()
# 获取电影详情信息
movie_info = MovieParticulars.objects.get(id=int(movie_id))
# 热门排行
fav_movie = Movie.objects.all().order_by(\'-fav_nums\')[:10]
# 收藏
is_fav = \'收藏\'
if request.user.is_authenticated:
if UserFavorite.objects.filter(user=request.user, movie_id=int(movie_id)):
is_fav = \'已收藏\'
# 显示评论
comments = UserComments.objects.filter(movie=movieId).order_by(\'-add_time\')
try:
page = request.GET.get(\'page\', 1)
except PageNotAnInteger:
page = 1
p = Paginator(comments,8) # 每页显示8个,从all_classification中取
comments_page = p.page(page)
# 显示评分
ratings=float(0)
if request.user.is_authenticated:
ratings=UserRatings.objects.filter(user=request.user, movie=movieId)
# 记录浏览
if request.user.is_authenticated:
if not UserBrowse.objects.filter(user= request.user, movie_id=int(movie_id)):
UserBrowse.objects.create(user=request.user, movie_id=int(movie_id))
return render(request, \'playMovie.html\', {
\'movie_info\': movie_info,
\'fav_movie\': fav_movie,
\'is_fav\': is_fav,
\'comments_page\': comments_page,
\'ratings\': ratings,
})
from django.db import models
class Movie(models.Model):
# movieId=models.IntegerField(‘电影ID’,default=0,)
name=models.CharField(‘电影名称’,max_length=50)
fav_nums=models.IntegerField(‘收藏人数’,default=0)
click_nums=models.IntegerField(‘点击数’,default=0)
add_time=models.DateTimeField(‘添加时间’,default=datetime.now)
class Meta:
verbose_name=\"电影\"
verbose_name_plural=verbose_name
def __str__(self):
return self.name
class MovieParticulars(models.Model):
MOVIE_TYPE=(
(‘aq’, u’爱情’),
(‘jq’, u’剧情’),
(‘xj’, u’喜剧’),
(‘wx’, u’武侠’),
(‘dz’, u’动作’),
(‘xy’, u’悬疑’),
(‘kb’, u’恐怖’),
(‘fz’, u’犯罪’),
(‘js’, u’惊悚’),
(‘kh’, u’科幻’),
(‘mx’, u’冒险’),
(‘dm’, u’动漫’),
(‘ty’, u’体育’),
(‘jl’, u’记录’),
(‘zz’, u’战争’)
)
REGION=(
(\'zg\',u\'中国\'),
(\'hg\',u\'韩国\'),
(\'rb\',u\'日本\'),
(\'om\',u\'欧美\')
)
LANGUAGE=(
(\'chinese\',u\'国语\'),
(\'cantonese\',u\'粤语\'),
(\'japanese\',u\'日语\'),
(\'korean\',u\'韩语\'),
(\'english\',u\'英语\'),
(\'french\',u\'法语\'),
(\'portuguese\',u\'葡萄牙语\'),
(\'spanish\', u\'西班牙语\')
)
name=models.ForeignKey(Movie,verbose_name=\'电影\',on_delete=models.CASCADE)
image = models.ImageField(\'封面图\', upload_to=\'movies/images/%Y/%m\', default=\'images/c3.jpg\', max_length=300)
movie_type=models.CharField(verbose_name=\'类型\',choices=MOVIE_TYPE,default=\'爱情\',max_length=10)
director=models.CharField(\'导演\',max_length=20)
protagonist=models.CharField(\'主演\',max_length=20)
region=models.CharField(verbose_name=u\'地区/国家\',choices=REGION,default=\'zg\',max_length=10)
language=models.CharField(verbose_name=u\'语言\',choices=LANGUAGE,default=\'chinese\',max_length=10)
release_data=models.DateTimeField(\'上映时间\',default=datetime.now)
intro=models.TextField(\'简介\')
add_time = models.DateTimeField(\"添加时间\", default=datetime.now)
class Meta:
verbose_name=\'电影详情\'
verbose_name_plural=verbose_name
def __str__(self):
return self.movie_type
class MovieResourse(models.Model):
name=models.ForeignKey(Movie,verbose_name=“电影”,on_delete=models.CASCADE)
download = models.FileField(“资源文件”, upload_to=“movies/resource/%Y/%m”, max_length=100)
add_time = models.DateTimeField(“添加时间”, default=datetime.now)
class Meta:
verbose_name=\'电影资源\'
verbose_name_plural=verbose_name