Hello, we publish stories on our website. Every story belongs to one or more classification (i.e. category), e.g. Travel, Food, Family (and of course the mighty important Hot Gossip ;-). A story can be published multiple times, possibly in different classifications.
The relevant bits of the model are below. This is not my code and I don't know how good the person was who wrote this. This is my first Django project, but I think I understand most of what's going on: class Story(models.Model): # fields like headline, content, etc. not shown here # Google groups seems to word-wrap at 75 characters... classifications = models.ManyToManyField(Classification, \ through="StoryPublishDate") class StoryPublishDate(models.Model): # some stuff omitted here, too story = models.ForeignKey(Story, related_name='publish_dates') classification = models.ForeignKey(Classification, \ related_name='story_publication') publish_date = models.DateTimeField() class Classification(our.own.TreeModel): # ... name = models.CharField(max_length=255) slug = models.SlugField(unique=True) Now I am creating the archive view. This is a 'per-classification' archive. It is supposed to have a yesterday, last 7 days, last 30 days section, so e.g. under http://our.domain.com/hot-gossip/archive in the yesterday web page section (a section is just an HTML div), stories should be shown that were published yesterday in the Hot Gossip classification. I am struggling to get the story filtering right. My problem is that there is more than one publish dates and possibly more than one classification: # for demo purposes, get the Hot Gossip classification by its slug; # comes in as parameter in the real system, of course... classification = Classification.get(slug='hot-gossip') # so far, I managed to come up with this for the story by classification # filtering; this does work, but only returns stories that were published # only once in the classification in question; it does not return stories # that were published multiple times, one or more of which in the # classification stories = Story.objects.filter(classifications = classification) # filtering by date range then seems pretty straight forward, e.g.: today = date.today() start_date = today - timedelta(days = 30) end_date = today - timedelta(days = 7) stories_month = \ stories.filter(publish_dates__publish_date__range=(start_date, end_date)) Of course, I thought of the 'native' approach to iterate over story.classifications.all() or story.publish_dates.all() in the view Python code and check if the classification and date match, but then I seem to be working with Python lists instead of Django QuerySets. This might be the way to go, using e.g. http://stackoverflow.com/questions/431628/how-to-combine-2-or-more-querysets-in-a-django-view, but I think this is a rather common problem, so maybe someone knows how to solve this more elegantly. Can anyone help me ? Cheers, Steve --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---