HI Eric, thanks for the reply.
I sort of found a solution, by poking through the contrib.syndication app, I added this function to my model: from django.template import loader def render(self): html_tmp = loader.get_template(self.html_template_name) html = loader.render_to_string(html_tmp.name, {'obj': self}) return html where self.html_template_name is the path + name of the template, and it's passed the calling model instance as 'obj'. Thanks! Rodrigo On May 19, 11:50 pm, Eric Abrahamsen <gir...@gmail.com> wrote: > On May 20, 2009, at 10:53 AM, Roberto Cea wrote: > > > > > I have a large amount of optional components (with a model for each > > one) that will be freely inserted by my users, and it would be > > impractical to render each one in a single large template. > > I want to give each component a ".render()" method, so I can just call > > that from the template. > > However, I don't want to have to put together each component's HTML in > > its model definition. Ideally, each component would have a > > corresponding template file, that would be added together with the > > page's other components' output to generate the complete page's HTML. > > Is there a way to specify, for each model, a small template-snippet > > file that will be used to represent it? Hopefully using Django > > standard template syntax? > > I'm not sure this will completely solve your problem, but in several > cases I've added python-only (non-database) attributes to models, > pointing at a template in my template dirs directory. That way you can > use generic code to render snippets for a variety of different models. > You could create a mixin class that provides the render() method, > using django's template rendering functions and a reference to > self.component_template, then have models subclass this mixin and > provide their own component_template attribute. > > Hope that's what you were looking for. > > Eric > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---