0

My problem is that I want to show all events that are for example in years 2016-17, 2017-18, 2018-19 etc, for example from 1.07.2016 to 31.08.2017. I use Django 1.6.

When I go to url: http://127.0.0.1:8000/en/production/2016-17 I got an error: Event matching query does not exist.

Event model:

class Event(models.Model):
    name = models.CharField('Name', max_length=255)
    start = models.DateField('Start')
    end = models.DateField('End')

    def __unicode__(self):
        return self.name

Here is my url:

url(r'^(?P<branch_slug>/production/(?P<year1>[0-9]{4})-(?P<year2>[0-9]{2})$', EventView.as_view()),

Here is my view:

class EventListView(ListView):

    def get_queryset(self):
        filter_ = {'online': True}
        season_start = Event.objects.get(start=datetime.date(int(self.kwargs['year1']), 7, 1))
        season_end = Event.objects.get(end=datetime.date(int(self.kwargs['year2']), 8, 31))
        filter_['start__gte'] = season_start
        filter_['end__lte'] = season_end
        return self.model.objects.filter(**filter_)

Please for help or some hint.

Mark
  • 15
  • 1
  • 6
  • season_start (and season_end) is a instance of Event. But you are using it as Date. Try to `filter_['start__gte'] = season_start.start` (and the same at season_end) for return a Date object. – Rafael Apr 04 '17 at 13:45
  • @Rafael Thanks for hint but I get an error in this place: `season_start = Event.objects.get(start=datetime.date(int(self.kwargs['year1']), 7, 1))` – Mark Apr 04 '17 at 13:49
  • Sorry. So, your database has no Event for the date specified. (same error [here](http://stackoverflow.com/questions/5508888/matching-query-does-not-exist-error-in-django)) – Rafael Apr 04 '17 at 14:13

1 Answers1

3

You're sending the first year as a four-digit parameter, but the second as only two parameters. So the database is looking for anything that hapepend between 2016 and 0017, which is unlikely to return any results.

Either use full four-digit years for the year2 param, or do something to interpolate the initial "20".

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895