Magnificent Models
Example methods and fields:
Poll.objects.all() - returns list of all
objects
p.question
Poll.objects.filter(question__startswith='Wha
t')
(This function was autogenerated by Django!)
A word about databases
Although Django certainly does do a lot for you, it
helps to know a bit about databases
When designing a model, useful to think about
good database practice
Good Database Design in a Nutshell:
1. Groups of related fields belong in the same table
2. New tables should be created for data fields that are
almost always empty
3. Most of the time the information contained in
unrelated fields will not need to be retrieved at the
same time, so those groups of fields should be in
separate fields as one another
Digestible Databases
Digestible Databases
Patient
ID
Last
Name
First
Name
Room
No.
(a) Patient Table
(b) Medication Table
Prescription
ID
Patient ID
Medication
Dosage
Instruction
(c) Schedule Table
Schedule
ID
Prescription
ID
Tim
e
Next Admin
Date
M T
W R
F
S
a
S
u
Example Database:
Views
Vivacious Views
Views are Python functions they make the web
pages users see
Can make use of models for getting data
Can use anything that Python has to offer!
...and there's A LOT Python can do! Makes for
interesting websites
|