Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # in models
  2. class Template(Base):
  3.     __tablename__ = 'template'
  4.     id = Column(Integer, primary_key=True)
  5.     description = Column(String(50))
  6.     contenu = Column(Text)
  7.    
  8.     def __init__(self, description=None, contenu=None):
  9.         self.description = description
  10.         self.contenu = contenu
  11.  
  12.     def __repr__(self):
  13.         return '<Template %r>' % (self.description)
  14.  
  15. class Page(Base):
  16.     __tablename__ = 'page'
  17.     id = Column(Integer, primary_key=True)
  18.     url = Column(String(50), unique=True)
  19.     titre = Column(String(100))
  20.     idTemplate = Column(Integer, ForeignKey('template.id'))
  21.  
  22.     def __init__(self, url=None, titre=None, idTemplate=0):
  23.         self.url = url
  24.         self.titre = titre
  25.         self.contenu = contenu
  26.  
  27.     def __repr__(self):
  28.         return '<Page %r>' % (self.titre)
  29.  
  30.  
  31. ## In My Views
  32. from dynamiqueweb.models import Page, Template
  33. retourPage = Page.query.filter_by(url='/').join(Template).first()
  34.    
  35. # For Exemple i want to acces to variable contenu in my Template class and to my titre variable in Page
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement