Am 15.04.2010 17:18 schrieb jo:
I tried it with the original template of
widgets.PaginateDataGrid()
when I click on data_fine...
*TypeError: ("can't compare datetime.datetime to NoneType",
This means you're still sorting in memory. Reasons could be that you
convert your query object to a list or set the max_sort parameter or
that you are using a property in your grid that is not a column in the
database. But if you setup everything properly, it will work.
Here are all relevant parts of my code. Try running this as a
quickstarted app and check where you are doing something different.
MODEL
-----
from sqlalchemy import Table, Column, ForeignKey
from sqlalchemy import String, DateTime
from turbogears.database import mapper, metadata
from sqlalchemy.orm import relation
specie_table = Table('specie', metadata,
Column('codice', String(8), primary_key=True),
Column('descrizione', String(32)),
Column('data_fine', DateTime, default=datetime.now),
Column('cod_gruppo_specie', String(8),
ForeignKey('gruppo_specie.codice')))
gruppo_specie_table = Table('gruppo_specie', metadata,
Column('codice', String(8), primary_key=True),
Column('descrizione', String(32)))
class Specie(object):
pass
class GruppoSpecie(object):
pass
mapper(Specie, specie_table)
mapper(GruppoSpecie, gruppo_specie_table,
properties=dict(
species=relation(Specie, backref='gruppo_specie')))
CONTROLLER
----------
from turbogears import controllers, expose, paginate
from turbogears.widgets import PaginateDataGrid
from model import Specie
col = PaginateDataGrid.Column
sortable = dict(sortable=True)
gridFields=[ #campi della grid
col('codice', title='codice', options=sortable),
col('descrizione', title='descrizione', options=sortable),
col('cod_gruppo_specie', title='gruppo specie',
options=sortable, getter=lambda s:
s.gruppo_specie and s.gruppo_specie.descrizione or ''),
col('data_fine', title='fine validita', options=sortable)]
class Root(controllers.RootController):
"""The root controller of the application."""
@expose(template="foo.templates.grid")
@paginate(var_name='records')
def index(self):
return dict(records=Specie.query(),
grid=PaginateDataGrid(fields=gridFields))
TEMPLATE
--------
<div py:replace="grid(records)"/>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.