main
wzy 6 months ago
parent 7ec5923340
commit 0807ba4b82

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="FacetManager">
<facet type="django" name="Django">
<configuration>
<option name="rootFolder" value="$MODULE_DIR$" />
<option name="settingsModule" value="Movie_recommendation_system/settings.py" />
<option name="manageScript" value="$MODULE_DIR$/manage.py" />
<option name="environment" value="&lt;map/&gt;" />
<option name="doNotUseTestRunner" value="false" />
<option name="trackFilePattern" value="migrations" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Django" />
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/templates" />
</list>
</option>
</component>
</module>

@ -0,0 +1,254 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="3588" name="Python" />
</Languages>
</inspection_tool>
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="218">
<item index="0" class="java.lang.String" itemvalue="greenlet" />
<item index="1" class="java.lang.String" itemvalue="yarg" />
<item index="2" class="java.lang.String" itemvalue="python-dateutil" />
<item index="3" class="java.lang.String" itemvalue="MarkupSafe" />
<item index="4" class="java.lang.String" itemvalue="pycparser" />
<item index="5" class="java.lang.String" itemvalue="coreschema" />
<item index="6" class="java.lang.String" itemvalue="docopt" />
<item index="7" class="java.lang.String" itemvalue="filelock" />
<item index="8" class="java.lang.String" itemvalue="backports.zoneinfo" />
<item index="9" class="java.lang.String" itemvalue="certifi" />
<item index="10" class="java.lang.String" itemvalue="gevent" />
<item index="11" class="java.lang.String" itemvalue="Werkzeug" />
<item index="12" class="java.lang.String" itemvalue="djangorestframework-jwt" />
<item index="13" class="java.lang.String" itemvalue="asgiref" />
<item index="14" class="java.lang.String" itemvalue="django-rest-swagger" />
<item index="15" class="java.lang.String" itemvalue="zope.interface" />
<item index="16" class="java.lang.String" itemvalue="gunicorn" />
<item index="17" class="java.lang.String" itemvalue="click" />
<item index="18" class="java.lang.String" itemvalue="simplejson" />
<item index="19" class="java.lang.String" itemvalue="platformdirs" />
<item index="20" class="java.lang.String" itemvalue="django-filter" />
<item index="21" class="java.lang.String" itemvalue="virtualenv" />
<item index="22" class="java.lang.String" itemvalue="charset-normalizer" />
<item index="23" class="java.lang.String" itemvalue="distlib" />
<item index="24" class="java.lang.String" itemvalue="openapi-codec" />
<item index="25" class="java.lang.String" itemvalue="PyMySQL" />
<item index="26" class="java.lang.String" itemvalue="idna" />
<item index="27" class="java.lang.String" itemvalue="PyJWT" />
<item index="28" class="java.lang.String" itemvalue="django-ckeditor" />
<item index="29" class="java.lang.String" itemvalue="cffi" />
<item index="30" class="java.lang.String" itemvalue="numpy" />
<item index="31" class="java.lang.String" itemvalue="requests" />
<item index="32" class="java.lang.String" itemvalue="importlib-metadata" />
<item index="33" class="java.lang.String" itemvalue="Jinja2" />
<item index="34" class="java.lang.String" itemvalue="django-prometheus" />
<item index="35" class="java.lang.String" itemvalue="sqlparse" />
<item index="36" class="java.lang.String" itemvalue="zipp" />
<item index="37" class="java.lang.String" itemvalue="urllib3" />
<item index="38" class="java.lang.String" itemvalue="djangorestframework" />
<item index="39" class="java.lang.String" itemvalue="itsdangerous" />
<item index="40" class="java.lang.String" itemvalue="zope.event" />
<item index="41" class="java.lang.String" itemvalue="django-cors-headers" />
<item index="42" class="java.lang.String" itemvalue="uritemplate" />
<item index="43" class="java.lang.String" itemvalue="six" />
<item index="44" class="java.lang.String" itemvalue="tzdata" />
<item index="45" class="java.lang.String" itemvalue="pipreqs" />
<item index="46" class="java.lang.String" itemvalue="prometheus-client" />
<item index="47" class="java.lang.String" itemvalue="pandas" />
<item index="48" class="java.lang.String" itemvalue="coreapi" />
<item index="49" class="java.lang.String" itemvalue="drf-extensions" />
<item index="50" class="java.lang.String" itemvalue="colorama" />
<item index="51" class="java.lang.String" itemvalue="Django" />
<item index="52" class="java.lang.String" itemvalue="django-js-asset" />
<item index="53" class="java.lang.String" itemvalue="itypes" />
<item index="54" class="java.lang.String" itemvalue="pytz" />
<item index="55" class="java.lang.String" itemvalue="Pillow" />
<item index="56" class="java.lang.String" itemvalue="alembic" />
<item index="57" class="java.lang.String" itemvalue="Flask-Script" />
<item index="58" class="java.lang.String" itemvalue="asn1crypto" />
<item index="59" class="java.lang.String" itemvalue="Flask-WTF" />
<item index="60" class="java.lang.String" itemvalue="SQLAlchemy" />
<item index="61" class="java.lang.String" itemvalue="cryptography" />
<item index="62" class="java.lang.String" itemvalue="Click" />
<item index="63" class="java.lang.String" itemvalue="python-editor" />
<item index="64" class="java.lang.String" itemvalue="Flask-SQLAlchemy" />
<item index="65" class="java.lang.String" itemvalue="WTForms" />
<item index="66" class="java.lang.String" itemvalue="Flask-Migrate" />
<item index="67" class="java.lang.String" itemvalue="ItsDangerous" />
<item index="68" class="java.lang.String" itemvalue="Mako" />
<item index="69" class="java.lang.String" itemvalue="Flask" />
<item index="70" class="java.lang.String" itemvalue="mysqlclient" />
<item index="71" class="java.lang.String" itemvalue="diff-match-patch" />
<item index="72" class="java.lang.String" itemvalue="django-crispy-forms" />
<item index="73" class="java.lang.String" itemvalue="PyYAML" />
<item index="74" class="java.lang.String" itemvalue="tablib" />
<item index="75" class="java.lang.String" itemvalue="django-import-export" />
<item index="76" class="java.lang.String" itemvalue="defusedxml" />
<item index="77" class="java.lang.String" itemvalue="httplib2" />
<item index="78" class="java.lang.String" itemvalue="xlwt" />
<item index="79" class="java.lang.String" itemvalue="et-xmlfile" />
<item index="80" class="java.lang.String" itemvalue="MarkupPy" />
<item index="81" class="java.lang.String" itemvalue="django-reversion" />
<item index="82" class="java.lang.String" itemvalue="chardet" />
<item index="83" class="java.lang.String" itemvalue="jdcal" />
<item index="84" class="java.lang.String" itemvalue="odfpy" />
<item index="85" class="java.lang.String" itemvalue="django-guardian" />
<item index="86" class="java.lang.String" itemvalue="future" />
<item index="87" class="java.lang.String" itemvalue="xadmin2" />
<item index="88" class="java.lang.String" itemvalue="xlrd" />
<item index="89" class="java.lang.String" itemvalue="django-formtools" />
<item index="90" class="java.lang.String" itemvalue="openpyxl" />
<item index="91" class="java.lang.String" itemvalue="mkl-fft" />
<item index="92" class="java.lang.String" itemvalue="Bottleneck" />
<item index="93" class="java.lang.String" itemvalue="wincertstore" />
<item index="94" class="java.lang.String" itemvalue="django-simpleui" />
<item index="95" class="java.lang.String" itemvalue="olefile" />
<item index="96" class="java.lang.String" itemvalue="smartchart" />
<item index="97" class="java.lang.String" itemvalue="typing-extensions" />
<item index="98" class="java.lang.String" itemvalue="mkl-random" />
<item index="99" class="java.lang.String" itemvalue="smartdb" />
<item index="100" class="java.lang.String" itemvalue="mkl-service" />
<item index="101" class="java.lang.String" itemvalue="numexpr" />
<item index="102" class="java.lang.String" itemvalue="sqlalchemy" />
<item index="103" class="java.lang.String" itemvalue="XlsxWriter" />
<item index="104" class="java.lang.String" itemvalue="djangorestframework-simplejwt" />
<item index="105" class="java.lang.String" itemvalue="import-export" />
<item index="106" class="java.lang.String" itemvalue="pip" />
<item index="107" class="java.lang.String" itemvalue="wheel" />
<item index="108" class="java.lang.String" itemvalue="setuptools" />
<item index="109" class="java.lang.String" itemvalue="pyparsing" />
<item index="110" class="java.lang.String" itemvalue="Markdown" />
<item index="111" class="java.lang.String" itemvalue="psutil" />
<item index="112" class="java.lang.String" itemvalue="django" />
<item index="113" class="java.lang.String" itemvalue="pymysql" />
<item index="114" class="java.lang.String" itemvalue="python-alipay-sdk" />
<item index="115" class="java.lang.String" itemvalue="django-threadlocals" />
<item index="116" class="java.lang.String" itemvalue="matplotlib" />
<item index="117" class="java.lang.String" itemvalue="pyqt5" />
<item index="118" class="java.lang.String" itemvalue="absl-py" />
<item index="119" class="java.lang.String" itemvalue="google-pasta" />
<item index="120" class="java.lang.String" itemvalue="protobuf" />
<item index="121" class="java.lang.String" itemvalue="tensorflow-estimator" />
<item index="122" class="java.lang.String" itemvalue="Automat" />
<item index="123" class="java.lang.String" itemvalue="html5lib" />
<item index="124" class="java.lang.String" itemvalue="pygame" />
<item index="125" class="java.lang.String" itemvalue="opt-einsum" />
<item index="126" class="java.lang.String" itemvalue="baidu-aip" />
<item index="127" class="java.lang.String" itemvalue="cycler" />
<item index="128" class="java.lang.String" itemvalue="gast" />
<item index="129" class="java.lang.String" itemvalue="constantly" />
<item index="130" class="java.lang.String" itemvalue="pyasn1-modules" />
<item index="131" class="java.lang.String" itemvalue="appdirs" />
<item index="132" class="java.lang.String" itemvalue="oauthlib" />
<item index="133" class="java.lang.String" itemvalue="astunparse" />
<item index="134" class="java.lang.String" itemvalue="PyDispatcher" />
<item index="135" class="java.lang.String" itemvalue="lxml" />
<item index="136" class="java.lang.String" itemvalue="soupsieve" />
<item index="137" class="java.lang.String" itemvalue="beautifulsoup4" />
<item index="138" class="java.lang.String" itemvalue="pywin32" />
<item index="139" class="java.lang.String" itemvalue="hyperlink" />
<item index="140" class="java.lang.String" itemvalue="opencv-contrib-python" />
<item index="141" class="java.lang.String" itemvalue="service-identity" />
<item index="142" class="java.lang.String" itemvalue="tifffile" />
<item index="143" class="java.lang.String" itemvalue="h5py" />
<item index="144" class="java.lang.String" itemvalue="wrapt" />
<item index="145" class="java.lang.String" itemvalue="kiwisolver" />
<item index="146" class="java.lang.String" itemvalue="attrs" />
<item index="147" class="java.lang.String" itemvalue="flatbuffers" />
<item index="148" class="java.lang.String" itemvalue="parsel" />
<item index="149" class="java.lang.String" itemvalue="tensorboard" />
<item index="150" class="java.lang.String" itemvalue="imageio" />
<item index="151" class="java.lang.String" itemvalue="cssselect" />
<item index="152" class="java.lang.String" itemvalue="pypiwin32" />
<item index="153" class="java.lang.String" itemvalue="scikit-image" />
<item index="154" class="java.lang.String" itemvalue="rsa" />
<item index="155" class="java.lang.String" itemvalue="decorator" />
<item index="156" class="java.lang.String" itemvalue="Scrapy3" />
<item index="157" class="java.lang.String" itemvalue="networkx" />
<item index="158" class="java.lang.String" itemvalue="queuelib" />
<item index="159" class="java.lang.String" itemvalue="qrcode" />
<item index="160" class="java.lang.String" itemvalue="pyttsx3" />
<item index="161" class="java.lang.String" itemvalue="pyasn1" />
<item index="162" class="java.lang.String" itemvalue="w3lib" />
<item index="163" class="java.lang.String" itemvalue="requests-oauthlib" />
<item index="164" class="java.lang.String" itemvalue="Keras-Preprocessing" />
<item index="165" class="java.lang.String" itemvalue="tensorflow" />
<item index="166" class="java.lang.String" itemvalue="selenium" />
<item index="167" class="java.lang.String" itemvalue="tensorboard-plugin-wit" />
<item index="168" class="java.lang.String" itemvalue="pyOpenSSL" />
<item index="169" class="java.lang.String" itemvalue="PyWavelets" />
<item index="170" class="java.lang.String" itemvalue="scipy" />
<item index="171" class="java.lang.String" itemvalue="google-auth-oauthlib" />
<item index="172" class="java.lang.String" itemvalue="opencv-python" />
<item index="173" class="java.lang.String" itemvalue="PyHamcrest" />
<item index="174" class="java.lang.String" itemvalue="packaging" />
<item index="175" class="java.lang.String" itemvalue="incremental" />
<item index="176" class="java.lang.String" itemvalue="pooch" />
<item index="177" class="java.lang.String" itemvalue="termcolor" />
<item index="178" class="java.lang.String" itemvalue="cachetools" />
<item index="179" class="java.lang.String" itemvalue="grpcio" />
<item index="180" class="java.lang.String" itemvalue="webencodings" />
<item index="181" class="java.lang.String" itemvalue="google-auth" />
<item index="182" class="java.lang.String" itemvalue="Twisted" />
<item index="183" class="java.lang.String" itemvalue="PyQt5" />
<item index="184" class="java.lang.String" itemvalue="django-bootstrap-toolkit" />
<item index="185" class="java.lang.String" itemvalue="python-crontab" />
<item index="186" class="java.lang.String" itemvalue="kombu" />
<item index="187" class="java.lang.String" itemvalue="redis" />
<item index="188" class="java.lang.String" itemvalue="pyrsistent" />
<item index="189" class="java.lang.String" itemvalue="eventlet" />
<item index="190" class="java.lang.String" itemvalue="django-ranged-response" />
<item index="191" class="java.lang.String" itemvalue="captcha" />
<item index="192" class="java.lang.String" itemvalue="django-tinymce" />
<item index="193" class="java.lang.String" itemvalue="django-registration-redux" />
<item index="194" class="java.lang.String" itemvalue="anyjson" />
<item index="195" class="java.lang.String" itemvalue="xadmin-django" />
<item index="196" class="java.lang.String" itemvalue="monotonic" />
<item index="197" class="java.lang.String" itemvalue="django-model-utils" />
<item index="198" class="java.lang.String" itemvalue="vine" />
<item index="199" class="java.lang.String" itemvalue="billiard" />
<item index="200" class="java.lang.String" itemvalue="jsonschema" />
<item index="201" class="java.lang.String" itemvalue="django-contrib-comments" />
<item index="202" class="java.lang.String" itemvalue="django-filters" />
<item index="203" class="java.lang.String" itemvalue="rcssmin" />
<item index="204" class="java.lang.String" itemvalue="dnspython" />
<item index="205" class="java.lang.String" itemvalue="rjsmin" />
<item index="206" class="java.lang.String" itemvalue="markdown2" />
<item index="207" class="java.lang.String" itemvalue="amqp" />
<item index="208" class="java.lang.String" itemvalue="django-appconf" />
<item index="209" class="java.lang.String" itemvalue="django-compressor" />
<item index="210" class="java.lang.String" itemvalue="django-jsonfield" />
<item index="211" class="java.lang.String" itemvalue="django-simple-captcha" />
<item index="212" class="java.lang.String" itemvalue="django-markdown-deux" />
<item index="213" class="java.lang.String" itemvalue="contrib" />
<item index="214" class="java.lang.String" itemvalue="django-crontab" />
<item index="215" class="java.lang.String" itemvalue="django-redis" />
<item index="216" class="java.lang.String" itemvalue="django-timezone-field" />
<item index="217" class="java.lang.String" itemvalue="icecola" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N802" />
<option value="N801" />
<option value="N806" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyStubPackagesAdvertiser" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<list>
<option value="PyQt5-stubs==5.15.6.0" />
</list>
</option>
</inspection_tool>
<inspection_tool class="Stylelint" enabled="true" level="ERROR" enabled_by_default="true" />
</profile>
</component>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/MoviesRecommend.iml" filepath="$PROJECT_DIR$/.idea/MoviesRecommend.iml" />
</modules>
</component>
</project>

@ -0,0 +1,3 @@
import pymysql
pymysql.install_as_MySQLdb()

@ -0,0 +1,104 @@
import os
# 项目路径
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# 项目秘钥
SECRET_KEY = 'bhml2023(140w8x3ktw=yzm0=@3h5wr=$$4s!g(s-^s7^@e5=kz'
# 调试模式
DEBUG = True
# 允许的主机
ALLOWED_HOSTS = []
# 注册app
INSTALLED_APPS = [
'django.contrib.admin', # 后台管理系统
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'movie' # 电影推荐系统
]
# 中间件
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
# 主路由
ROOT_URLCONF = 'Movie_recommendation_system.urls'
# 模板文件配置
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'movie.context_processors.movie_user'
],
'builtins': ['django.templatetags.static']
},
},
]
WSGI_APPLICATION = 'Movie_recommendation_system.wsgi.application'
# 数据库配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_movie_recommend',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': '3306'
}
}
# 密码验证
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# 国际化配置
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# 静态文件 (CSS, JavaScript, Images)
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
# AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.AllowAllUsersModelBackend']

@ -0,0 +1,10 @@
from django.contrib import admin
from django.urls import path, include
from .views import index, star
urlpatterns = [
path('admin/', admin.site.urls), # 后台管理系统
path('', index), # 首页
path('movie/', include('movie.urls')), # 电影推荐系统子路由
]

@ -0,0 +1,11 @@
from django.shortcuts import render
# 首页
def index(request):
return render(request, 'index.html')
# 打分
def star(request):
return render(request, 'movie/star.html')

@ -0,0 +1,7 @@
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Movie_recommendation_system.settings")
application = get_wsgi_application()

File diff suppressed because it is too large Load Diff

@ -0,0 +1,12 @@
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Movie_recommendation_system.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"项目环境配置异常,请检查!"
) from exc
execute_from_command_line(sys.argv)

@ -0,0 +1,56 @@
from django.contrib import admin
from movie.models import User, Movie, Genre, Movie_hot, Movie_rating, Movie_similarity
admin.site.site_title = "电影推荐系统后台管理系统"
admin.site.site_header = "电影推荐系统-后台管理系统"
admin.site.index_title = "电影推荐系统"
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'password', 'email']
search_fields = ['name', 'email']
list_per_page = 12
ordering = ['id']
@admin.register(Genre)
class GenreAdmin(admin.ModelAdmin):
list_display = ['id', 'name']
search_fields = ['name']
# list_filter = ['name']
list_per_page = 12
ordering = ['id']
@admin.register(Movie)
class MovieAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'imdb_id', 'time', 'release_time', 'intro', 'director', 'writers', 'actors', ]
search_fields = ['name', 'intro', 'writers', 'actors']
list_per_page = 6
ordering = ['id']
@admin.register(Movie_hot)
class Movie_hotAdmin(admin.ModelAdmin):
list_display = ['id', 'movie', 'rating_number']
search_fields = ['movie__name']
list_per_page = 6
ordering = ['-rating_number']
@admin.register(Movie_rating)
class Movie_ratingAdmin(admin.ModelAdmin):
list_display = ['id', 'user', 'movie', 'score', 'comment']
search_fields = ['user__name', 'movie__name']
list_per_page = 6
ordering = ['-score']
@admin.register(Movie_similarity)
class Movie_similarityAdmin(admin.ModelAdmin):
list_display = ['id', 'movie_source', 'movie_target', 'similarity']
search_fields = ['movie_source__name', 'movie_source__name']
list_per_page = 6
ordering = ['-similarity']

@ -0,0 +1,6 @@
from django.apps import AppConfig
class MovieConfig(AppConfig):
name = 'movie'
verbose_name = "电影推荐系统"

@ -0,0 +1,14 @@
from .models import User
def movie_user(request):
user_id = request.session.get('user_id')
context = {}
if user_id:
try:
user = User.objects.get(pk=user_id)
context['movie_user'] = user
except:
pass
return context

@ -0,0 +1,65 @@
from django import forms
from movie.models import User, Movie_rating
class RegisterForm(forms.ModelForm):
password_repeat = forms.CharField(max_length=256)
def get_errors(self):
errors = self.errors.get_json_data()
errors_lst = []
for messages in errors.values():
for message_dict in messages:
for key, message in message_dict.items():
if key == 'message':
errors_lst.append(message)
return errors_lst
def clean(self):
cleaned_data = super(RegisterForm, self).clean()
pwd = cleaned_data.get('password')
password_repeat = cleaned_data.get('password_repeat')
if pwd != password_repeat:
raise forms.ValidationError(message='两次密码输入不一致!')
return cleaned_data
class Meta:
model = User
fields = ['name', 'password', 'email']
class LoginForm(forms.ModelForm):
name = forms.CharField(max_length=128)
remember = forms.IntegerField(required=False)
class Meta:
model = User
fields = ['password']
def get_errors(self):
errors = self.errors.get_json_data()
errors_lst = []
for messages in errors.values():
for message_dict in messages:
for key, message in message_dict.items():
if key == 'message':
errors_lst.append(message)
return errors_lst
class CommentForm(forms.ModelForm):
def clean(self):
cleaned_data = super(CommentForm, self).clean()
score = cleaned_data.get('score')
if score == 0:
raise forms.ValidationError(message='评分不能为空!')
else:
return cleaned_data
class Meta:
model = Movie_rating
fields = ['score', 'comment']

@ -0,0 +1,102 @@
# Generated by Django 3.2.16 on 2023-11-26 06:06
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Genre',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
options={
'db_table': 'Genre',
},
),
migrations.CreateModel(
name='Movie',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256, verbose_name='电影名')),
('imdb_id', models.IntegerField()),
('time', models.CharField(blank=True, max_length=256)),
('release_time', models.CharField(blank=True, max_length=256)),
('intro', models.TextField(blank=True)),
('director', models.CharField(blank=True, max_length=256)),
('writers', models.CharField(blank=True, max_length=256)),
('actors', models.CharField(blank=True, max_length=512)),
('genre', models.ManyToManyField(to='movie.Genre')),
],
options={
'db_table': 'Movie',
},
),
migrations.CreateModel(
name='Movie_rating',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('score', models.FloatField()),
('comment', models.TextField(blank=True)),
('movie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='movie.movie')),
],
options={
'db_table': 'Movie_rating',
},
),
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True)),
('password', models.CharField(max_length=256)),
('email', models.EmailField(max_length=254, unique=True)),
('rating_movies', models.ManyToManyField(through='movie.Movie_rating', to='movie.Movie')),
],
options={
'db_table': 'User',
},
),
migrations.CreateModel(
name='Movie_similarity',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('similarity', models.FloatField()),
('movie_source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_source', to='movie.movie')),
('movie_target', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='movie_target', to='movie.movie')),
],
options={
'ordering': ['-similarity'],
},
),
migrations.AddField(
model_name='movie_rating',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='movie.user'),
),
migrations.CreateModel(
name='Movie_hot',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rating_number', models.IntegerField()),
('movie', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='movie.movie')),
],
options={
'db_table': 'Movie_hot',
'ordering': ['-rating_number'],
},
),
migrations.AddField(
model_name='movie',
name='movie_similarity',
field=models.ManyToManyField(through='movie.Movie_similarity', to='movie.Movie'),
),
]

@ -0,0 +1,111 @@
from django.db import models
from django.db.models import Avg
class Genre(models.Model):
name = models.CharField(max_length=100, verbose_name="类型")
class Meta:
db_table = 'Genre'
verbose_name = '电影类型'
verbose_name_plural = '电影类型'
def __str__(self):
return self.name
class Movie(models.Model):
name = models.CharField(max_length=256, verbose_name="电影名")
imdb_id = models.IntegerField(verbose_name="imdb_id")
time = models.CharField(max_length=256, blank=True, verbose_name="时长")
genre = models.ManyToManyField(Genre, verbose_name="类型")
release_time = models.CharField(max_length=256, blank=True, verbose_name="发行时间")
intro = models.TextField(blank=True, verbose_name="简介")
director = models.CharField(max_length=256, blank=True, verbose_name="导演")
writers = models.CharField(max_length=256, blank=True, verbose_name="编剧")
actors = models.CharField(max_length=512, blank=True, verbose_name="演员")
movie_similarity = models.ManyToManyField("self", through="Movie_similarity", symmetrical=False,
verbose_name="相似电影")
class Meta:
db_table = 'Movie'
verbose_name = '电影信息'
verbose_name_plural = '电影信息'
def __str__(self):
return self.name
def get_score(self):
result_dct = self.movie_rating_set.aggregate(Avg('score'))
try:
result = round(result_dct['score__avg'], 1)
except TypeError:
return 0
else:
return result
def get_user_score(self, user):
return self.movie_rating_set.filter(user=user).values('score')
def get_score_int_range(self):
return range(int(self.get_score()))
def get_genre(self):
genre_dct = self.genre.all().values('name')
genre_lst = []
for dct in genre_dct.values():
genre_lst.append(dct['name'])
return genre_lst
def get_similarity(self, k=5):
similarity_movies = self.movie_similarity.all()[:k]
return similarity_movies
class Movie_similarity(models.Model):
movie_source = models.ForeignKey(Movie, related_name='movie_source', on_delete=models.CASCADE, verbose_name="来源电影")
movie_target = models.ForeignKey(Movie, related_name='movie_target', on_delete=models.CASCADE, verbose_name="目标电影")
similarity = models.FloatField(verbose_name="相似度")
class Meta:
verbose_name = '电影相似度'
verbose_name_plural = '电影相似度'
class User(models.Model):
name = models.CharField(max_length=128, unique=True, verbose_name="用户名")
password = models.CharField(max_length=256, verbose_name="密码")
email = models.EmailField(unique=True, verbose_name="邮箱")
rating_movies = models.ManyToManyField(Movie, through="Movie_rating")
def __str__(self):
return "<USER:( name: {:},password: {:},email: {:} )>".format(self.name, self.password, self.email)
class Meta:
db_table = 'User'
verbose_name = '用户信息'
verbose_name_plural = '用户信息'
class Movie_rating(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, unique=False, verbose_name="用户")
movie = models.ForeignKey(Movie, on_delete=models.CASCADE, unique=False, verbose_name="电影")
score = models.FloatField(verbose_name="分数")
comment = models.TextField(blank=True, verbose_name="评论")
class Meta:
db_table = 'Movie_rating'
verbose_name = '电影评分信息'
verbose_name_plural = '电影评分信息'
class Movie_hot(models.Model):
movie = models.ForeignKey(Movie, on_delete=models.CASCADE, verbose_name="电影名")
rating_number = models.IntegerField(verbose_name="评分人数")
class Meta:
db_table = 'Movie_hot'
verbose_name = '最热电影'
verbose_name_plural = '最热电影'

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 B

@ -0,0 +1,24 @@
Musical
War
Crime
Romance
Fantasy
Drama
Music
Sci-Fi
Action
Comedy
Biography
Family
Horror
Short
Documentary
Film-Noir
Animation
Adventure
News
Mystery
Sport
History
Thriller
Western

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save