7, Laboratory introduction module
The laboratory profile module is mainly used to introduce the laboratory profile and the basic information of other laboratories of the college, mainly including the laboratory profile of Binhai college, public teaching multimedia laboratory, public computer laboratory, professional laboratory of computer science department, professional laboratory of electronic science department, professional laboratory of economic management department, professional laboratory of foreign language department Professional laboratories of the Department of law and politics, the Department of environmental science and engineering, the Department of art, the Department of finance, and the Department of management science and engineering. The brief introduction of the laboratory of Binhai university mainly introduces the overall situation of the laboratory, and other laboratories are introduced in detail according to the classification of the laboratory. The business module diagram is as follows:
1. Model design
from django.db import models
from DjangoUeditor.models import UEditorField
import django.utils.timezone as timezone
import time
from loginApp.models import BMXXB,RYXXB
Create your models here.
m_y = (time.strftime("%y"))
m_m = (time.strftime("%m"))
Create your models here.
#(3) Laboratory type table (LABLXB)
class LABLXB(models.Model):
LABLXBH = models.CharField('lab type number ', max_length=2,unique=True)
LABLXMC = models.CharField('laboratory type name ', max_length=50)
XH = models.IntegerField('serial number ', default=0)
SYZT = models.IntegerField('usage status', default=0)
CJSJ = models.DateTimeField('creation time ', default = timezone.now)
class Meta: verbose_name = 'Laboratory type maintenance' verbose_name_plural = verbose_name ordering = ("-CJSJ",) def __str__(self): return self.LABLXMC
#(11) Laboratory information sheet (LABXXB)
class LABXXB(models.Model):
LABLXBH = models.ForeignKey('LABLXB ', on_delete=models.CASCADE,verbose_name =' laboratory type number ')
LABBH = models.CharField('lab number ', max_length=50)
LABMC = models.CharField('laboratory name ', max_length=100)
LABMS = UEditorField(u 'content',
default='',
width=1000,
height=300,
imagePath='lab/images/'+m_y+'/'+m_m+'/',
filePath='lab/files/'+m_y+'/'+m_m+'/',
upload_settings={'imageMaxSizing':1024000},
)
BMBH = models.ForeignKey('loginApp.BMXXB ', related_name = "labxx_bmbhs", on_delete=models.CASCADE,verbose_name =' department number ')
VIEWS = models.PositiveIntegerField('visits', default=0)
FBRR = models.ForeignKey('loginApp.RYXXB ', on_delete=models.CASCADE,verbose_name =' publisher ')
CJSJ = models.DateTimeField('creation time ', default = timezone.now)
class Meta: verbose_name = 'Laboratory information maintenance' verbose_name_plural = verbose_name ordering = ("-CJSJ",) def __str__(self): return self.LABMC
2. Migrate (compile) database
python manage.py makemigrations
3. Create database
python manage.py migrate
4. Create super user
python manage.py createsuperuser
5. Background management design
from django.contrib import admin
from .models import *
Register your models here.
class LABXXBAdmin(admin.ModelAdmin):
style_fields = {'LABMS': 'ueditor'}
admin.site.register(LABXXB,LABXXBAdmin)
admin.site.register(LABLXB)
6. View design
from django.shortcuts import render
from .models import *
from django.core.paginator import Paginator
from django.shortcuts import get_object_or_404
from pyquery import PyQuery as pq
def labinfo(request):
lablxs = LABLXB.objects.all().order_by('-XH')
return render(request,'labinfo.html',{'active_menu':'about','lablxs':lablxs,})
def labs(request,newName):
#Resolve the requested news type
lablxs = LABLXB.objects.all().order_by('-XH')
submenu = newName
strname=''
# print(newName)
# if newName == '1':
# strname = '01'
# elif newName == '2':
# strname = '02'
# elif newName == '3':
# strname = '03'
# else:
# strname = '09'
# print(strname)
strname = newName
lablxbh = LABLXB.objects.get(LABLXBH=strname).LABLXBH
# print(lablxbh)
lablxmc = LABLXB.objects.get(LABLXBH=strname).LABLXMC
# print(lablxmc)
labList = LABXXB.objects.all().filter(LABLXBH=lablxbh).order_by('-CJSJ') for labxx in labList: html = pq(labxx.LABMS) # Parsing html content using pq method labxx.mytxt = pq(html)('p').text() # Intercept html paragraph text # paging p = Paginator(labList, 5) if p.num_pages <= 1: pageData = '' else: page = int(request.GET.get('page', 1)) labList = p.page(page) left = [] right = [] left_has_more = False right_has_more = False first = False last = False total_pages = p.num_pages page_range = p.page_range if page == 1: right = page_range[page:page + 2] print(total_pages) if right[-1] < total_pages - 1: right_has_more = True if right[-1] < total_pages: last = True elif page == total_pages: left = page_range[(page - 3) if (page - 3) > 0 else 0:page - 1] if left[0] > 2: left_has_more = True if left[0] > 1: first = True else: left = page_range[(page - 3) if (page - 3) > 0 else 0:page - 1] right = page_range[page:page + 2] if left[0] > 2: left_has_more = True if left[0] > 1: first = True if right[-1] < total_pages - 1: right_has_more = True if right[-1] < total_pages: last = True pageData = { 'left': left, 'right': right, 'left_has_more': left_has_more, 'right_has_more': right_has_more, 'first': first, 'last': last, 'total_pages': total_pages, 'page': page, } # print(lablxs) # print(labList) return render( request, 'labList.html', { 'active_menu': 'labs', 'sub_menu': submenu, 'lablxmc': lablxmc, 'lablxs':lablxs, 'labList': labList, 'pageData': pageData, })
def labDetail(request, id):
lablxs = LABLXB.objects.all().order_by('-XH')
mylab = get_object_or_404(LABXXB, id=id) mylab.VIEWS += 1 mylab.save() print(mylab) return render(request, 'labDetail.html', { 'active_menu': 'labs', # 'lablxmc': lablxmc, 'lablxs':lablxs, 'mylab': mylab, })
7. Access routing design
from django.urls import path
from . import views
app_name = 'aboutApp'
urlpatterns = [
path('labinfo / ', views.labinfo, name =' labinfo '), # lab overview
path('labs/str:newName / ', views.labs, name =' Labs'), # lab list
path('labDetail/int:id / ', views.labDetail, name =' labDetail '), # lab details
]
8. Introduction to laboratory template design
{% extends "base.html" %}
{% load static %}
{% block title %}
Introduction to the laboratory of Binhai University
{% endblock %}
{% block content %}
- {% for lablx in lablxs %}
- {{lablx.LABLXMC}}
- {% endfor %}
Binhai College of Nankai University was established in 2004 with the approval of the Ministry of education. Since its establishment, the college has attached great importance to laboratory construction. Since its establishment, it has invested more than 90 million yuan to build the laboratory. In the construction, according to the needs of teaching, scientific research and discipline construction, it adheres to "overall planning, step-by-step implementation, resource sharing and urgent use first" All laboratories of the college can give full play to their benefits.
At present, according to the characteristics of various disciplines and specialties, the college has 96 teaching laboratories, with a total area of 12516.47 square meters, 6124 teaching instruments and equipment in use, a total value of 68.4239 million yuan, 62 full-time and part-time laboratory managers, and 4614775 person hours of annual teaching tasks.
The college has 93 public multimedia classrooms and 11 public computer laboratories, equipped with advanced computer teaching equipment. Diversified experimental teaching courses are carried out by means of simulation, practical operation, demonstration and virtual simulation.
{% extends "base.html" %}
{% load static %}
{% block title %}
{{lablxmc}}
{% endblock %}
{% block content %}
- {% for lablx in lablxs %}
- {{lablx.LABLXMC}}
- {% endfor %}
{% for mylab in labList %} <tr> <td> <div class="news-model"> <a href="{% url 'aboutApp:labDetail' mylab.id %}"><b>{{mylab.LABMC}}</b></a> <span>[{{mylab.CJSJ|date:"Y-m-d"}}]</span> <p> <!-- Add a brief description of the news --> Summary:{{mylab.mytxt|truncatechars:"110"}}... </p> </div> </td> </tr> {% endfor %} </table> {% if pageData %} <div class="paging"> <ul id="pages" class="pagination"> {% if pageData.first %} <li><a href="?page=1">1</a></li> {% endif %} {% if pageData.left %} {% if pageData.left_has_more %} <li><span>...</span></li> {% endif %} {% for i in pageData.left %} <li><a href="?page={{i}}">{{i}}</a></li> {% endfor %} {% endif %} <li class="active"><a href="?page={{pageData.page}}"> {{pageData.page}}</a></li> {% if pageData.right %} {% for i in pageData.right %} <li><a href="?page={{i}}">{{i}}</a></li> {% endfor %} {% if pageData.right_has_more %} <li><span>...</span></li> {% endif %} {% endif %} {% if pageData.last %} <li><a href="?page={{pageData.total_pages}}"> {{pageData.total_pages}}</a></li> {% endif %} </ul> </div> {% endif %} </div> </div>
10. Laboratory details and formwork design
{% extends "base.html" %}
{% load static %}
{% block title %}
{{mylab.LABLXBH}}
{% endblock %}
{% block content %}
<!-- Side navigation bar --> <div class="col-md-3"> <div class="model-title"> {{mylab.LABLXBH}} </div> <div class="model-list"> <ul class="list-group"> <li class="list-group-item"> <a href="{% url 'aboutApp:labinfo'%}">Introduction to the laboratory of Binhai University</a> </li> </ul> </div> <div class="model-list"> <ul class="list-group"> {% for lablx in lablxs %} <li class="list-group-item" id='{{lablx.LABLXMC}}'> <a href="{% url 'aboutApp:labs' lablx.LABLXBH %}">{{lablx.LABLXMC}}</a> </li> {% endfor %} </ul> </div> </div> <div class="col-md-9"> <div class="model-details-product-title"> {{mylab.LABMC}} <div class="model-foot">Published on:{{mylab.CJSJ|date:"Y-m-d"}} Number of Views:{{mylab.VIEWS}}</div> </div> <div class="model-details"> {{ mylab.LABMS | safe }} </div> </div>
Statement: the implementation process code of this case refers to the textbook Python Web development from introduction to practice. Some codes are directly referenced. The detailed website is: https://blog.csdn.net/qianbin3200896/article/details/106454741 , if you have any copyright problems, please contact me, thank you.