Commits

Atsushi Odagiri committed edc8885

add demonstration to use foreign key
apply style to show.html .

Comments (0)

Files changed (2)

src/alchemyadmin/demo/__init__.py

     display_name = Column(Unicode(255))
     description = Column(UnicodeText)
     birthday = Column(DateTime)
+    job_id = Column(Integer, ForeignKey('job.job_id'))
+    job = relation("Job", backref='users')
 
 
+    def __unicode__(self):
+        return self.display_name
+
+
+class Job(Base):
+    __tablename__ = 'job'
+    job_id = Column(Integer, primary_key=True)
+    name = Column(Unicode(255), unique=True)
+
+    def __unicode__(self):
+        return self.name
+    
+
 def make_app(global_conf, **app_conf):
     from alchemyadmin import Application
     conf = global_conf.copy()
     u.birthday = datetime.now()
     u.description = """ This is demo user."""
     session.add(u)
+
+    for j in (u"programmer", u"engineer", u"sales guy"):
+        job = Job()
+        job.name = j
+        session.add(job)
+
     session.commit()
 
-    app = Application(conf, User)
+    app = Application(conf, User, Job)
+
     import os
     app = SharedDataMiddleware(app, {
             '/css':os.path.join(os.path.dirname(__file__), 'static', 'css')

src/alchemyadmin/templates/model/show.html

+{%extends "base.html" %}
+{%block content %}
 {{model}}
 <table>
 {{form.render()}}
 </table>
+{%endblock %}