As @dentemm pointed out, to do filtering on datetime fields, strings representing date must be converted to datetime objects
. My suggestion is to use datetime field. Pass year string as you are already doing and then in the views convert date string to a datetime object to do filtering
import datetime
def get_queryset(self):
start=datetime.strptime('1-1-'+self.kwargs['year1'], '%m-%d-%Y')
end=datetime.strptime('12-31-'+self.kwargs['year2'], '%m-%d-%Y')
season = Events.objects.get(start=start, end=end)
filter_['start__gte'] = season.start
filter_['start__lte'] = season.end
return self.model.objects.filter(**filter_)
datetime.strptime('1-1-'+self.kwargs['year1'], '%m-%d-%Y')
will create datetime object for start date with date as 1st of january for given start date string and datetime.strptime('12-31-'+self.kwargs['year2'], '%m-%d-%Y')
will create datetime object for end date with date as 31st of december for given end date string. To make sure all objects created within end date is returned by query you may do something like
`end_date = datetime.strptime('31-12-'+self.kwargs['year1']+'T23:59:59.999999', '%m-%d-%YT%H:%M:%S.%f')`
As @Alasdair mnetioned in one of the comments change (?P<year2>[0-9]{2}) to (?P<year2>[0-9]{4})
to accept 4 digit year string from url