I recommend writing a custom template tag.  (http://
www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags).

So you would have for example:
{ list_member_events object }  <!--object is assumed to be a Member
instance that will be passed to you template tag code-->

Then in your template tag code you would be able to handle the logic
that is a little too complex to achieve elegantly with the standard
template tags.  This isn't much different than handling the logic in
the view function itself, but in my opinion the view functions should
be focused solely on pulling together the data for an action and
performing any special processing required in preparation to hand off
to the presentation layer.  Semantically, its easy to fall into a trap
and associate "view" with presentation layer but I prefer to think of
"view" as more analogous to a database view - a collection of data
that is pulled together based on a set of conditions.  The job of the
view is done when the set of data has been pulled together and made
ready to hand off to the presentation layer - without any regard to
how that data will be presented.  The template tag is taking on the
task of formatting that data into a specific markup to be rendered.
Now you have uncoupled your presentation from your business or
application logic and you could reuse that same view for other actions
in your application without having to special case the code for how
that data will actually be rendered :)

Cheers
-Brian



On Jun 14, 1:55 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Thanks for the idea, but that doesn't quite work either.  If someone
> only has 3 events, then the for loop runs through 3 times, and I end
> up with only three TD's.  I'm pretty sure what I need can't be
> accomplished in template code.
>
> I think I need to assign all the variables in view code, then send the
> resulting information to the template.  Something like:
>
> for event in events.objects.all():
> if event = "golfing", then golfer = "1"
> else golfer ="0"
>
> if event = "hiking', then hiker = "1"
> else hiker = "0"
>
> ...
>
> or something.  I'll dig more, comparing data like this seems similar
> to something someone would do for "tagging" posts in a blog
> application.  I'll start there.
>
> On Jun 13, 6:40 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > You just need something like:
> >  {% for p in object.events.all %}
> >       {% if p.event_name %}
> >           <td>{{ p.event_name }},</td>
> >       {% else %}><td></td>
> >       {% endif %}
> >  {% endfor %}
>
> > You could put the whole row in the IF, if you like.
>
> > On Jun 12, 8:55 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > > I think that requires more logic in the template than possible.
>
> > > My brain says tot do exactly what you suggest.  But my template looks
> > > similar to this:
> > >                 {% for p in object.events.all %}
> > >                 <td>
> > >                         {{ p.event_name }},
> > >                 </td>
> > >                 {% endfor %}
>
> > > If the Member isn't registered to one of the events, then I don't get
> > > a <td></td> for that event, and it throws off the rest of the format
> > > for the table...
>
> > > On Jun 12, 6:32 pm, Kelvin Nicholson <[EMAIL PROTECTED]> wrote:
>
> > > > [snip
>
> > > > > The trouble I'm having is, if someone is not assigned to an event, I
> > > > > get nothing displayed (duh, there's not an event); except I'm
> > > > > displaying this in a table, and if I don't have any data, then the
> > > > > cell formatting doesn't line up correctly.
>
> > > > [snip]
>
> > > > I just quickly perused your email; if the only problem you are having is
> > > > the loop creating the table row/column when there isn't any actual data,
> > > > couldn't you just create an {% if object %} in the template, and adjust
> > > > the formatting accordingly?
>
> > > > Just a quick thought,
> > > > Kelvin


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to