Re: no-database models?

2006-12-04 Thread Bill de hOra

[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.

I would have used an "event" rather than a "day" to model this. You can 
still (sensibly imo) argue that these are different things that have 
time series relation and not the same thing that happens repeatedly.

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

event
   ...
   date
   type: fk event_type
   meta : one to many

event_type:
   ...

event_meta:
   ...
   event: fk event

or you could use a generic table. They might give you relational 
heartburn, but they're designed for applying a relation to varying types 
(or disjoint types that wouldn't naturally have a common superclass) . 
The canonical usecase in django are applying comments to any model, or 
for tagging.  If you like how the comment api works, they might be for you.

cheers
Bill

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



Re: no-database models?

2006-12-04 Thread DavidA

[EMAIL PROTECTED] wrote:
> We're driving right past each other on the information
> superhighway.
>  Thanks for your advice, Russ. It still seems to me that a
> many-to-many relationship between days and events would be desirable,
> for the same reasons that all many-to-many relationships are desirable.
>
>  In my case, I don't want to record minutes at a particular meeting
> (for example) -- I just want to be able to publish the fact that the
> meeting is happening tonight, as it does every third Saturday at 7 p.m.
> For my purposes, it seems very unDRY to have to put a new record in the
> database every time that third Saturday rolls around.
>
>  Very best,
>
>  Hank Sims

Hank,

I'm a little confused. Your example uses a ForeignKey to relate Meeting
to MyDay but above you say you'd like a many-to-many relationship. Have
you tried:

   class MyDay:
 def __init__(self, date):
 self.id = date.toordinal()
 self.date = date

 class Concert(models.Model):
 title = models.CharField(maxlength=50)
 description = models.CharField(maxlength=50)
 date = models.ManyToManyField(MyDay)

 class Meeting(models.Model):
 title = models.CharField(maxlength=50)
 description = models.CharField(maxlength=50)
 date = models.ManyToManyField(MyDay)

Which *should* allow this in your templates:

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

Or maybe I'm misunderstanding what you are trying to do?

BTW, here is more info on M2M's:
http://www.djangoproject.com/documentation/models/many_to_many/

-Dave


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



Re: no-database models?

2006-12-03 Thread [EMAIL PROTECTED]

 We're driving right past each other on the information
superhighway.
 Thanks for your advice, Russ. It still seems to me that a
many-to-many relationship between days and events would be desirable,
for the same reasons that all many-to-many relationships are desirable.

 In my case, I don't want to record minutes at a particular meeting
(for example) -- I just want to be able to publish the fact that the
meeting is happening tonight, as it does every third Saturday at 7 p.m.
For my purposes, it seems very unDRY to have to put a new record in the
database every time that third Saturday rolls around.

 Very best,

 Hank Sims


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



Re: no-database models?

2006-12-03 Thread Russell Keith-Magee
On 12/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>   The other part, which I forgot to mention, is that I'd like to be
> able to have an easy many-to-many relationship between days and, say,
> meetings. A particular meeting can happen every other Tuesday, and it
> seems a waste to have to enter a new record for it twice a month.


I would argue that it if there are two meetings, there are two distinct
database entities that need to be recorded separately. If attendance at the
two meetings are different, or if you wanted to store the minutes of each
individual meeting, there is no way in your model to distinguish which
meeting had which attendance, or which set of minutes.

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


Re: no-database models?

2006-12-03 Thread Russell Keith-Magee
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
-~--~~~~--~~--~--~---


Re: no-database models?

2006-12-03 Thread [EMAIL PROTECTED]

  The other part, which I forgot to mention, is that I'd like to be
able to have an easy many-to-many relationship between days and, say,
meetings. A particular meeting can happen every other Tuesday, and it
seems a waste to have to enter a new record for it twice a month.

 Hank


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



Re: no-database models?

2006-12-03 Thread [EMAIL PROTECTED]

 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.
  Or am I being obtuse?

  Thanks, 

  Hank


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



Re: no-database models?

2006-12-03 Thread Russell Keith-Magee
On 12/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>   Of course, I could just run out 10 years worth of days in a
> database table to get the same effect, but that seems like a kludge. As
> does every other method of tackling this particular problem that I've
> been able to come up with.


Is there any particular reason that you have defined a 'day' model instance,
rather than just using a DateField on the Concert and Meeting models?

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