Retrive table from postgresql and display it using python turbogears

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2009
Posts: 12
Reputation: goldy736 is an unknown quantity at this point 
Solved Threads: 0
goldy736 goldy736 is offline Offline
Newbie Poster

Retrive table from postgresql and display it using python turbogears

 
0
  #1
Aug 29th, 2009
hi ,
i just started working in python , am using postgresql connected using turbo gears , python .
I have connected to DB modifying the dev.py ,
I want to display a created table from postgre sql in web browser using python turbo gears ,
my table in the DB is product_category
i have created product_category.kid with following code
  1.  
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml"
  6. xmlns:py="http://purl.org/kid/ns#"
  7. py:extends="master.kid">
  8.  
  9. <head>
  10. <title>Product Category: ${product_category.name}</title>
  11. </head>
  12.  
  13. <body>
  14. <table id="product-info">
  15. <tr>
  16. <td class="fld">Name:</td>
  17. <td class="val"><span py:replace="product_category.name" /></td>
  18. </tr>
  19. <tr>
  20. <td class="fld">ID</td>
  21. <td class="val"><span py:replace="product_category.id" /></td>
  22. </tr>
  23. </table>
  24. </body>
  25. </html>

And controllers.py is
  1.  
  2. import turbogears as tg
  3. from turbogears import controllers, expose
  4.  
  5. class Root(controllers.Root):
  6.  
  7. @expose("project2.templates.product_category")
  8. def index(self):
  9. from model import Product_Category
  10. product_category = Product_Category.selectBy(parent=None)[0]
  11. return dict(product_category=product_category)
  12.  
  13. @expose("project2.templates.product_category")
  14. def product_category(self, product_categoryID):
  15. from model import Product_Category
  16. product_category = Product_Category.get(product_categoryID)
  17. return dict(product_category=product_category)
with model.py as follows,
  1.  
  2. import pkg_resources
  3. pkg_resources.require("SQLObject>=0.10.1")
  4. from turbogears.database import PackageHub
  5. # import some basic SQLObject classes for declaring the data model
  6. # (see http://www.sqlobject.org/SQLObject.html#declaring-the-class)
  7. from sqlobject import SQLObject, SQLObjectNotFound, RelatedJoin
  8. # import some datatypes for table columns from SQLObject
  9. # (see http://www.sqlobject.org/SQLObject.html#column-types for more)
  10. from sqlobject import StringCol, UnicodeCol, IntCol, DateTimeCol
  11. from sqlobject import ForeignKey, UnicodeCol, IntCol, DateTimeCol
  12. from sqlobject import MultipleJoin, UnicodeCol, IntCol, DateTimeCol
  13. from sqlobject import CurrencyCol, UnicodeCol, IntCol, DateTimeCol
  14.  
  15. __connection__ = hub = PackageHub('project2')
  16.  
  17.  
  18. class Product_Category(SQLObject):
  19. name = StringCol(length=64)
  20. parent_id = IntCol(default=None)

when i run the code in cmd prompt tg-admin start-project.py

connecting to browser i have the following error :

  1. ProgrammingError: relation "product__category" does not exist

its been a day am trying to sort out . please any one can guide me out .

Thank you !
Last edited by goldy736; Aug 29th, 2009 at 9:14 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC