【问题标题】:Looking for input in model design for Django Schools在 Django Schools 的模型设计中寻找输入
【发布时间】:2010-09-25 13:57:00
【问题描述】:

今天我开始了一个小项目来创建一个基于 Django 的学校管理程序。我目前正在设计模型及其对应关系。作为 Django 和一般关系数据库的新手,我想要一些输入。

在我向您展示当前的模型布局之前,您需要了解该程序的用途。请记住,我的目标是让各个学校和整个学校系统都可以使用该软件。

特点: - 创建多所学校
- 跟踪每所学校的学生人数
- 跟踪学生人口统计数据、家长联系信息等。
- 等级书
- 成绩单
- 跟踪纪律记录。
- 费用表和付款跟踪
- 生成报告(学生活动、学生成绩单、班级进度、按人口统计的进度、付款报告、按学生班级和人口统计的纪律报告)
-- 自动向家长发送 PDF 报告电子邮件以获取学生报告。

鉴于这些功能要求,这是我目前拥有的模型布局: 型号

* Person
      o ID: char or int
      o FirstName: char
      o MiddleName: char
      o FamilyName: char
      o Sex: multiple choice
      o Ethnicity: multiple choice
      o BirthDate: date
      o Email: char
      o HomePhone: char
      o WordPhone: char
      o CellPhone: char
      o Address: one-to-one with Location
* Student (inherent Person)
      o Classes: one-to-many with Class
      o Parents: one-to-many with Parent
      o Account: one-to-one with PaymentSchedule
      o Tasks: one-to-many with Tasks
      o Diciplin: one-to-many with Discipline
* Parent (inherent Person)
      o Children: one-to-many with Student
* Teacher (inherent Person)
      o Classes: one-to-many with Class
* Location
      o Address: char
      o Address2: char
      o Address3: char
      o City: char
      o StateProvince: char
      o PostalCode: char
      o Country: multiple choice
* Course
      o Name: char
      o Description: text field
      o Grade: int
* Class
      o School: one-to-one with School
      o Course: one-to-one with Course
      o Teacher: one-to-one with Teacher
      o Students: one-to-many with Student
* School
      o ID: char or int
      o Name: char
      o Location: one-to-one with location
* Tasks
      o ID: auto increment
      o Type: multiple choice (assignment, test, etc.)
      o DateAssigned: date
      o DateCompleted: date
      o Score: real
      o Weight: real
      o Class: one-to-one with class
      o Student: one-to-one with Student
* Discipline
      o ID: auto-increment
      o Discription: text-field
      o Reaction: text-field
      o Students: one-to-many with Student
* PaymentSchedule
      o ID: auto-increment
      o YearlyCost: real
      o PaymentSchedule: multiple choice
      o ScholarshipType: multiple choice, None if N/A
      o ScholarshipAmount: real, 0 if N/A
      o Transactions: one-to-many with Payments
* Payments
      o auto-increment
      o Amount: real
      o Date: date

如果您对如何改进这方面有任何想法,我很乐意为他们服务!

更新

我已经编写了最初的 models.py 代码,这可能需要很多的爱。如果您想看看,甚至想加入该项目,请查看链接。
http://bazaar.launchpad.net/~djangoschools/djangoschools/trunk/files

【问题讨论】:

  • 将这样的问题设为社区 wiki 可能是个好主意,这样我们就可以直接对其进行编辑。
  • 检查。随心所欲地编辑!

标签: python django django-models


【解决方案1】:

学生没有班级。他/她参加了一个有他们的班级(在名册中)。这是查看班级情况的另一种方式。 (请注意模型的名称。这只是因为我倾向于不命名任何“类”,因为这样很容易发生名称冲突。)

class SchoolClass(models.Model):
    teacher = models.ManyToManyField(Teacher, related_name='teachers')
    student = models.ManyToManyField(Student, related_name='students')
    prerequisites = models.ForeignKey('self')
    startdate = models.DateField()
    enddate = models.DateField()
    ... and so on ...

这更自然,因为您可以与学生一起上课并根据学生列表进行出勤,或者以自然的方式汇总成绩、学生年龄等。

【讨论】:

    【解决方案2】:

    我建议您不要担心底层关系数据库。是的,您需要了解外键是什么以及多对多和一对多之间的区别等,但是您应该根据 Django 类来考虑您的模型。无论如何,这就是你必须编写它们的方式,所以这就是我要开始的地方。 Django documenation on models 很棒,对您有很大帮助。

    我想这里的每个人都会很乐意帮助你学习 Python 课程;您应该使用 Django 重写您的示例。例如,您的 Person 表如下所示:

    from django.db import models
    
    SEX_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female')
    )
    
    ETHNICITY_CHOICES = (
        # follow the same format as SEX_CHOICES:
        # (database_value, human_friendly_name)
    )
    
    class Person(models.Model):
        first_name   = models.CharField(max_length=200)
        middle_name  = models.CharField(max_length=200)
        familiy_name = models.CharField(max_length=200) 
    
        sex = models.CharField(max_length=1, choices=SEX_CHOICES)
        ethnicity  = models.CharField(max_length=1, choices=ETHNICITY_CHOICES)
        birth_date = models.DateField()
    
        email = models.EmailField()
        home_phone = models.CharField(max_length=10) # USA phone numbers
        work_phone = models.CharField(max_length=10)
        cell_phone = models.CharField(max_length=10)
        address = models.ForeignKey(Location)
    
    class Location(models.Model):
        # left as an exercise for the reader
    
    # more classes...
    

    【讨论】:

    • 感谢您的建议。我将在本周末或下周初编写模型类。完成后,我一定会在此处发布链接。另外,我可能会在 Launchpad.net 上启动一个 Django Schools 项目,因此人们可以直接贡献代码。
    【解决方案3】:

    一些可能的问题:

    对于位置对象,如果将来需要为一个人保存家庭地址、工作地址等怎么办?电子邮件地址和电话号码也是如此 - 我会将电话号码作为自己的对象。

    在您的地址对象中包含一个 Address_3。

    【讨论】:

    • 好点。怎么样:我将一对一链接从 Person 到 Location 更改为一对多,并在 location 中添加一个 Name 字段。我认为这将允许任何人(或子类)列出任意数量的地址。顺便说一句,你为什么要分开电话号码?
    【解决方案4】:

    您应该将付款(交易)链接到相关人员。

    【讨论】:

    • Student 的每个实例都有一个 PaymentSchedule,它又链接到多个 Payments。考虑到这一点,您是否还认为有必要将每个付款链接到学生?
    【解决方案5】:

    嘿...我同意...看起来不错。有人建议我在所有表上使用自动增量,以确保每条记录上确实有一个唯一的 ID。如果你想走那条路,那是你的选择。

    【讨论】:

    • Django 会为你做这个,所以不需要自己添加。
    【解决方案6】:

    看起来是一个有趣的项目。请注意,Django 具有比 SQL 更高级别的类型,因此您可以使用电子邮件地址类型之类的东西。

    如果您打算定位GAE,您应该找到一个同样丰富的set of model types。

    【讨论】:

      【解决方案7】:

      快速浏览一下,我认为它相当全面。或许您应该允许多位教师参与一门课程,并允许在家长和学生之间重复使用地址/位置。

      作为一般规则,我会说您应该开始实施,然后您会发现需要改进的地方。

      【讨论】:

      • 感谢您的建议,我会考虑的。你认为我的人际关系可以改善吗(我认为这听起来永远很有趣!)?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 2015-11-03
      • 2021-05-01
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多