On 12/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>      Russ,
>
>      Because it seems like the cleanest way of pulling together a wide
> variety of content that all pertains to a particular day, or list of
> days.
>      The alternative, it seems to me, is running seperate queries on
> Concerts, Meetings, DrinkSpecials, BallGames, etc., then passing all of
> those to the template. And things get stickier still if I'm talking
> about several days. If I could employ a one-to-many relationship
> between the Day instance and all these other models, that's just one
> queryset, and it's easier to slice and sort.


Ok; so you want to use a template context of:

context = TemplateContext({
   'myday' : Day.objects.get(date=date.today())
})

with a template of:

{% for concert in myday %}
    {{ concert.title}} {{ concert.description }}
{% endfor %}
{% for meeting in myday %}
    {{ meeting.title}} {{ meeting.description }}
{% endfor %}

The alternative is using a context of:

context = TemplateContext({
  'todaysConcerts': Concerts.objects.filter(date=date.today()),
  'todaysMeetings':  Meetings.objects.filter(date=date.today())
})

with a template of
{% for concert in todaysConcerts %}
    {{ concert.title}} {{ concert.description }}
{% endfor %}
{% for meeting in todaysMeetings %}
    {{ meeting.title}} {{ meeting.description }}
{% endfor %}

I don't see why the former is in any way preferable to the latter,
especially if you have to mess around with optimizing the Date model.

If your problem is the repeated query clause in the context, remember all
the fancy things you can do with dictionaries and the ** operator:

query = {
   'date':date.today()
}
context = TemplateContext({
   'todaysConcerts': Concerts.objects.filter(**query),
   'todaysMeetings': Meetings.objects.filter(**query)
})

You could even go completely dynamic:

context = TemplateContext(
    dict([('todays'+model.name, model.objects.filter(date=date.today())) for
model in [Concerts, Meetings]])
)

Yours,
Russ Magee %-)


--~--~---------~--~----~------------~-------~--~----~
 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