给一个系统,基于Django的学员健康档案管理系统

时间: 2023-12-07 08:05:02 浏览: 44
好的,以下是一个简单的基于Django的学员健康档案管理系统的设计: 1. 数据库模型设计: ```python from django.db import models class Student(models.Model): name = models.CharField(max_length=50) age = models.IntegerField() gender = models.CharField(max_length=10) phone = models.CharField(max_length=20) email = models.EmailField() class HealthRecord(models.Model): student = models.ForeignKey(Student, on_delete=models.CASCADE) date = models.DateField() height = models.FloatField() weight = models.FloatField() temperature = models.FloatField() blood_pressure = models.CharField(max_length=20) ``` 2. 视图函数和模板设计: ```python from django.shortcuts import render, redirect from .models import Student, HealthRecord from datetime import datetime def add_student(request): if request.method == 'POST': name = request.POST['name'] age = request.POST['age'] gender = request.POST['gender'] phone = request.POST['phone'] email = request.POST['email'] student = Student.objects.create(name=name, age=age, gender=gender, phone=phone, email=email) return redirect('add_health_record', student_id=student.id) return render(request, 'add_student.html') def add_health_record(request, student_id): student = Student.objects.get(id=student_id) if request.method == 'POST': date = datetime.strptime(request.POST['date'], '%Y-%m-%d').date() height = request.POST['height'] weight = request.POST['weight'] temperature = request.POST['temperature'] blood_pressure = request.POST['blood_pressure'] HealthRecord.objects.create(student=student, date=date, height=height, weight=weight, temperature=temperature, blood_pressure=blood_pressure) return redirect('student_detail', student_id=student.id) return render(request, 'add_health_record.html', {'student': student}) def student_detail(request, student_id): student = Student.objects.get(id=student_id) health_records = HealthRecord.objects.filter(student=student).order_by('-date') return render(request, 'student_detail.html', {'student': student, 'health_records': health_records}) ``` add_student.html 模板: ```html <form method="post"> {% csrf_token %} <label for="name">姓名</label> <input type="text" id="name" name="name"><br> <label for="age">年龄</label> <input type="text" id="age" name="age"><br> <label for="gender">性别</label> <input type="text" id="gender" name="gender"><br> <label for="phone">电话</label> <input type="text" id="phone" name="phone"><br> <label for="email">邮箱</label> <input type="email" id="email" name="email"><br> <button type="submit">提交</button> </form> ``` add_health_record.html 模板: ```html <form method="post"> {% csrf_token %} <label for="date">日期</label> <input type="date" id="date" name="date"><br> <label for="height">身高</label> <input type="text" id="height" name="height"><br> <label for="weight">体重</label> <input type="text" id="weight" name="weight"><br> <label for="temperature">体温</label> <input type="text" id="temperature" name="temperature"><br> <label for="blood_pressure">血压</label> <input type="text" id="blood_pressure" name="blood_pressure"><br> <button type="submit">提交</button> </form> ``` student_detail.html 模板: ```html <h1>{{ student.name }}</h1> <p>年龄:{{ student.age }}</p> <p>性别:{{ student.gender }}</p> <p>电话:{{ student.phone }}</p> <p>邮箱:{{ student.email }}</p> <h2>健康档案</h2> <ul> {% for health_record in health_records %} <li>{{ health_record.date }}:身高{{ health_record.height }}cm,体重{{ health_record.weight }}kg,体温{{ health_record.temperature }}℃,血压{{ health_record.blood_pressure }}</li> {% endfor %} </ul> ``` 3. URL 配置: ```python from django.urls import path from . import views urlpatterns = [ path('add_student/', views.add_student, name='add_student'), path('add_health_record/<int:student_id>/', views.add_health_record, name='add_health_record'), path('student_detail/<int:student_id>/', views.student_detail, name='student_detail'), ] ``` 这个系统包含两个主要的模型:学员(Student)和健康档案(HealthRecord),学员可以有多条健康档案记录。视图函数包含添加学员、添加健康档案和查看学员详情三个功能。模板文件负责渲染页面。URL 配置将 URL 映射到对应的视图函数上。

相关推荐

最新推荐

recommend-type

基于Django框架的管理系统的设计与开发

以新疆昭苏地区的马产业为例搭建了一个基于Django框架的马匹竞拍管理系统。该系统将昭苏马产业与信息技术相结合,采用Django网页开发框架、Bootstrap响应式网页开发技术、Python语言和MTV的设计模式实现了商品信息...
recommend-type

Python3+Django3开发简单的人员管理系统

Python3+Django3开发简单的人员管理系统 1、创建工程和应用 1.1 使用pycharm创建项目 原创文章 66获赞 47访问量 7057 关注 私信 展开阅读全文 作者:哒哒哒~
recommend-type

Python django框架开发发布会签到系统(web开发)

 最近学习了虫师的发布会签到系统demo,结合自己所学django知识,对demo重新塑造了一下。也是为了练练手,巩固知识。现在就分享一下成果~  Django工作流  学习django web开发,先来简单了解一下django的工作机制...
recommend-type

Django用户登录与注册系统的实现示例

主要介绍了Django用户登录与注册系统的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

Ubuntu系统搭建django+nginx+uwsgi的教程详解

主要介绍了Ubuntu系统搭建django+nginx+uwsgi的思路详解,本文分步骤给大家介绍的非常详细,具有一定的参考借鉴价值 ,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。