Introduction to Django #3Introduction to Django #3 SPARCS `08 서우석 (pipoket) `09 Summer SP ARCS Seminar`09 Summer SP ARCS Seminar SPARCS
▶ You know DatabaseYou know Database Table Row Record Column Attribute DB (Relational DBMS) DB SPARCS
▶ Relational DB FormatRelational DB Format Table Column Row SPARCS
▶ You already have it!You already have it! Your own “Database”! Your own “Format” SPARCS
▶ What if?What if?data(file)data(file) CollisionCollision SPARCS
▶ So we use…So we use…models.py SPARCS
▶ Django = OODBDjango = OODB Student Student.id SPARCS
▶ What`s the difference?What`s the difference? Originally… SELECT id, name, age FROM student WHERE id= SELECT id, name, age FROM student WHERE id= SPARCS
▶ What`s the difference?What`s the difference? In Django… SPARCS from model import student res = student.get(id=“ ”) print res.name from model import student res = student.get(id=“ ”) print res.name
▶Difference! You don`t know SQL You don`t know DBMS Python You only know Python You know python! You know python! OK! SPARCS
▶ Creating TableCreating Table models.py Table is also Object! Making Class == Making Table SPARCS
▶ Creating Table – Field Types Data TypeField Name integerIntegerField() string (length fixed)CharField(max_length=100) string (long length)TextField() datetimeDateTimeField() booleanBooleanField() SPARCS
▶ Notify Django about TableNotify Django about Table SPARCS13 Add your application with models.py settings.py
▶ Adding DataAdding Data Row is also Object! YOU NEED THIS TO SAVE SPARCS
▶ Retrieving dataRetrieving data Getting row object When not found Row == Object !! SPARCS
▶ Modifying dataModifying data Get object to modify Modify and Save! SPARCS
▶ Deleting dataDeleting data Get object to delete Delete! SPARCS
▶Summary Table Define class in models Column Define Fields in class of models Row Create Object with class in models Get Function in class of models Modify Get object, Modify and Save Delete Get object, Call delete function SPARCS
▶Practice Change homework of 2 weeks ago. Make it work with database. ….. Okay, Let`s do it together SPARCS