arpho

entities.py

Jan 12th, 2012
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. from elixir import *
  2. import os
  3. dbfile="regioni.sql"
  4. class Regione(Entity):
  5. """
  6. A task for your TODO list.
  7. """
  8. using_table_options(useexisting=True)
  9. using_options(tablename='regione')
  10. nome = Field(Unicode,required=True)
  11. id = Field(Integer, colname="id", primary_key=True)
  12.  
  13.  
  14.  
  15. def __repr__(self):
  16. return "regione: "+self.nome
  17.  
  18. class Comune(Entity):
  19. using_table_options(useexisting=True)
  20. using_options(tablename='comune')
  21. nome=Field(Unicode)
  22. id=Field(Integer, colname="id", primary_key=True)
  23. provincia_id=Field(Integer)
  24.  
  25.  
  26.  
  27. class Provincia(Entity):
  28. """
  29. A task for your TODO list.
  30. """
  31. using_table_options(useexisting=True)
  32. using_options(tablename='provincia')
  33. nome = Field(Unicode,required=True)
  34.  
  35. id = Field(Integer,default=None,primary_key=True)
  36. regione_id=Field(Integer)
  37.  
  38.  
  39. def __repr__(self):
  40. return "regione: "+self.nome
  41.  
  42.  
  43.  
  44.  
  45. saveData=None
  46.  
  47. def initDB():
  48.  
  49.  
  50. metadata.bind = "sqlite:///%s"%dbfile
  51. metadata.bind.echo = False
  52. setup_all()
  53. if not os.path.exists(dbfile):
  54. create_all()
  55.  
  56. # This is so Elixir 0.5.x and 0.6.x work
  57. # Yes, it's kinda ugly, but needed for Debian
  58. # and Ubuntu and other distros.
  59.  
  60. global saveData
  61. import elixir
  62. if elixir.__version__ < "0.6":
  63. saveData=session.flush
  64. else:
  65. saveData=session.commit
  66.  
  67.  
  68.  
  69. def main():
  70.  
  71. # Initialize database
  72. initDB()
  73.  
  74. for task in Provincia.query.all():
  75.  
  76. print task
  77.  
  78. # Create two tags
  79. #green=Tag(name=u"green")
  80. #red=Tag(name=u"red")
  81.  
  82. #Create a few tags and tag them
  83. # d = date.fromordinal(730920)
  84. # tarea1=Task(text=u"Buy tomatos",tags=[red],date=d)
  85. # tarea2=Task(text=u"Buy chili",tags=[red],date=d)
  86. #tarea3=Task(text=u"Buy lettuce",tags=[green],date=d)
  87. #tarea4=Task(text=u"Buy strawberries",tags=[red,green],date=d)
  88. #saveData()
Advertisement
Add Comment
Please, Sign In to add comment