2008-12-05 41 views
2

今天我開始創建一個基於Django的學校管理程序的小項目。我目前正在設計模型及其相應的關係。對於Django和一般的關係數據庫來說相當新,我想要一些輸入。在Django Schools的模型設計中尋找輸入

在向您展示當前的模型佈局之前,您需要了解該程序的用途。請記住,這是我的目標,該軟件可供各個學校和整個學校系統使用。

特點: - 創建多個學校
- 每所學校
跟蹤學生羣體 - 跟蹤學生的成績,家長聯繫方式等
- 級書籍
- 成績單
- 跟蹤紀律處分的紀錄。
- 費用安排和付款跟蹤
- 生成報告(學生活動,學生成績單,班級的進步,受人口,付款進度報告,由學生課和人口學科報告)
- 自動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

+0

將這樣的問題製作成社區wiki可能是個好主意,所以我們可以直接編輯它。 – Powerlord 2008-12-05 20:56:22

+0

檢查。編輯你心中的內容! – crashsystems 2008-12-05 21:29:34

回答

1

從簡單的看,我認爲它相當全面。也許你應該允許多個教師參加課程,並允許在父母和學生之間重複使用地址/位置。

作爲一般規則,我會說你應該開始實施,然後你會發現你需要改進的地方。

+0

感謝您的建議,我會研究。你認爲我的關係可以改進嗎(我不認爲這樣會讓人聽起來很有趣!)? – crashsystems 2008-12-05 19:58:35

0

看起來像一個有趣的項目。請注意,Django比SQL有更高級的類型,所以你可以使用諸如電子郵件地址類型之類的東西。

如果您打算將目標鎖定爲GAE,則應該找到類似豐富的set of model types

0

嘿......我同意......它看起來不錯。有人建議我在所有表上使用自動增量,以確保每條記錄上都有一個唯一的ID。如果您想要走這條路線,這是您的選擇。

+0

Django爲你做這件事,所以你不需要自己添加它。 – 2008-12-05 22:17:05

0

您應該將paiement(交易)鏈接到相關人員。

+0

Student的每個實例都有一個PaymentSchedule,它又鏈接到多個Payments。考慮到這一點,你是否也認爲有必要將每筆付款鏈接到學生? – crashsystems 2008-12-05 21:56:41

1

一些可能出現的問題:

對於位置對象,如果你需要保留的家庭地址,工作地址等一個人的未來?同樣的電子郵件地址和電話號碼 - 我會有電話號碼作爲自己的對象。

在地址對象上包含Address_3。

+0

好點。那麼怎麼樣:我將從人員到位置的一對一鏈接更改爲一對多,並在位置中添加一個名稱字段。我認爲這將允許任何人(或子類)具有列出的任意數量的地址。 順便說一句,你爲什麼要分開電話號碼? – crashsystems 2008-12-05 21:59:48

0

我會建議你不要擔心下屬關係數據庫。是的,你需要了解外鍵是什麼以及多對多和一對多之間的區別,但是你應該根據Django類來考慮你的模型。這就是你無論如何都必須寫的,所以這就是我要開始的地方。 Django documenation on models是偉大的,並會幫助你很多。

我認爲這裏的每個人都會很樂意幫助您使用Python類;你應該用Django重寫你的例子。例如,您的人員表格如下所示:

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... 
0

學生沒有班級。他/她參加有他們的班級(名冊中)。這是查看課堂情況的另一種方法。 (注意模型的名稱。這只是因爲我傾向於不要,因爲它很容易陷入名稱衝突這樣的名求什麼「班」。)

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 ... 

這是更自然的,因爲你可以與學生類和按照學生名單參加考試,或以自然的方式彙總成績,學生年齡等。