Skip to content

Commit

Permalink
add compatibility for django < 1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
llazzaro committed Oct 4, 2016
1 parent 09c5df8 commit 84d5b03
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions schedule/periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import calendar as standardlib_calendar

from django.conf import settings
from django.db.models import prefetch_related_objects
try:
from django.db.models import prefetch_related_objects
except ImportError:
from django.db.models.query import prefetch_related_objects

from django.utils.translation import ugettext
from django.utils.encoding import python_2_unicode_compatible
from django.template.defaultfilters import date as date_filter
Expand Down Expand Up @@ -79,7 +83,10 @@ def _get_sorted_occurrences(self):
occurrences.append(occurrence)
return occurrences

prefetch_related_objects(self.events, 'occurrence_set')
try:
prefetch_related_objects(self.events, 'occurrence_set')
except AttributeError:
prefetch_related_objects(self.events, ['occurrence_set'])
for event in self.events:
event_occurrences = event.get_occurrences(self.start, self.end, clear_prefetch=False)
occurrences += event_occurrences
Expand Down

0 comments on commit 84d5b03

Please sign in to comment.