+class NotesView(ListView):
+ def get_queryset(self):
+ self.letters = ["0-9"] + [chr(a) for a in range(ord('a'), ord('z')+1)]
+ self.letter = self.kwargs.get('letter')
+
+ objects = Note.objects.all()
+ if self.letter == "0-9":
+ objects = objects.filter(sort_key__regex=r"^[0-9]")
+ elif self.letter:
+ objects = objects.filter(sort_key__startswith=self.letter)
+ return objects
+
+ def get_context_data(self, **kwargs):
+ context = super(NotesView, self).get_context_data(**kwargs)
+ context['letter'] = self.letter
+ context['letters'] = self.letters
+ return context