On Apr 3, 4:47 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> On Tuesday 03 April 2007 07:12, George Sakkis wrote: > > > I'm trying to add json to a controller method that works fine when > > returning html; when returning json though I get NoApplicableMethods > > if the returned dict contains instances of my models. Could the > > problem be that my models are based on Elixir/SqlAlchemy and jsonify > > doesn't know how to handle them ? If this is the case, shouldn't > > there be the same generic mechanism to convert aribitrary objects to > > dicts, as it happens when passing them to kid/genshi templates ? > > Without you providing the actual traceback, one can only guess... Pasted it at http://paste.turbogears.org/paste/1183. > But I'd say yes, that is the reason. For SO there is some generic > serialization of model objects, but it only works to a certain extend - it > won't serialize any related objects for example. Ok, I see. So the way I now handle it is by checking if cherrypy.request.params.get('tg_format') == 'json' and return the appropriate dict. Kind of kludge but works for now. > And you are wrong assuming that arbitrary objects are converted when being > passed to templates. They are passed as-is. You're right in general, I was thinking of the dictify_value() generic but this applies to CompoundInputWidgets, not to arbitrary templates. Thanks, George --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

