Advertisement
Guest User

is1proj

a guest
Mar 4th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.10 KB | None | 0 0
  1. from pony.orm import *
  2.  
  3. db=Database()
  4.  
  5. class Admin(db.Entity):
  6.     ime=Required(str)
  7.     prezime=Required(str)
  8.     email=Required(str)
  9.     password=Required(str)
  10.  
  11. class SalterRadnik(db.Entity):
  12.     ime=Required(str)
  13.     prezime=Required(str)
  14.     email=Required(str)
  15.     password=Required(str)
  16.  
  17. class Student(db.Entity):
  18.     ime = Required(str)
  19.     prezime= Required(str)
  20.     email= Required(str)
  21.     password= Required(str)
  22.     budzet= Required(int)
  23.     racun= Required(int)
  24.     predmeti = Optional("Slusa")
  25.  
  26. class Predmet(db.Entity):
  27.     naziv=Required(str)
  28.     studenti=Optional("Slusa")
  29.  
  30. class Slusa(db.Entity):
  31.     student=Required(Student)
  32.     predmet=Required(Predmet)
  33.     PrimaryKey(student,predmet)
  34.     ispit=Optional("Ispit")
  35.  
  36.  
  37.  
  38. class Rok(db.Entity):
  39.     naziv=Required(str)
  40.     ispit=Optional("Ispit")
  41.  
  42. class Ispit(db.Entity):
  43.     slusa=Required(Slusa)
  44.     rok=Required(Rok)
  45.     PrimaryKey(slusa,rok)
  46.     ocena=Required(int)
  47.     datum=Required(str)
  48.  
  49.  
  50.  
  51.  
  52.  
  53. db.bind('mysql', host='localhost', user='python', passwd='python', db='python')
  54. db.generate_mapping(create_tables=True)
  55.  
  56. # s=Student(ime='ime!',prezime='prezime',email='mail',password='sadasd',budzet=1,racun=21121)
  57. # p=Predmet(naziv='sssass')
  58.  
  59.  
  60. @db_session
  61. def print_person_name(x):
  62.     p=Predmet(naziv=x)
  63.     s=Student(ime='iame',prezime='prezime!!!!!',email='mail',password='sadasd',budzet=1,racun=21121)
  64.     sl=Slusa(student=s,predmet=p)
  65.     commit()
  66.  
  67.  
  68.  
  69. print_person_name("peraaa")
  70.  
  71.  
  72. def logged(id):
  73.     with db_session:
  74.         s=select(s for s in Student if 1==s.id)[:]
  75.         return s[0]
  76. s=logged(1)
  77.  
  78.  
  79. @db_session
  80. def insertStudent(newStud):
  81.     s=Student(ime=newStud[0],prezime='ssss',email='mail',password='sadasd',budzet=1,racun=21121)
  82.     commit()
  83.  
  84. @db_session
  85. def findByID(id):
  86.     with db_session:
  87.         s=select(s for s in Student if id==s.id)[:]
  88.         return s[0]
  89. @db_session
  90. def updateStudent(id,toUpdate):
  91.     s=findByID(id)
  92.     s.ime=toUpdate[0]
  93.     s.prezime=toUpdate[1]
  94.     s.email=toUpdate[2]
  95.     s.password=toUpdate[3]
  96.     s.budzet=toUpdate[4]
  97.     s.racun=toUpdate[5]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement