Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_queryset(self):
- user = self.request.user
- queryset = Notification.objects.annotate(Count('album'), Count('video'))
- notifs_of_albums = queryset.filter(album__count=1)
- notifs_of_videos = queryset.filter(video__count=1)
- notifs_of_albums_to_user_ids = []
- notifs_of_videos_to_user_ids = []
- for subscription in user.subscriptions.all():
- if subscription.content_type.model == 'artist':
- notif = notifs_of_albums.filter(
- album__artist=subscription.artist.first(),
- album__release_date__gte=subscription.datetime_committed
- ).first()
- try:
- notifs_of_albums_to_user_ids.append(notif.pk)
- except AttributeError:
- pass
- elif subscription.content_type.model == 'channel':
- notif = notifs_of_videos.filter(
- video__channel=subscription.channel.first(),
- video__release_datetime__gte=subscription.datetime_committed
- ).first()
- try:
- notifs_of_videos_to_user_ids.append(notif.pk)
- except AttributeError:
- pass
- notifs_of_albums_to_user = notifs_of_albums.filter(
- pk__in=notifs_of_albums_to_user_ids
- )
- notifs_of_videos_to_user = notifs_of_videos.filter(
- pk__in=notifs_of_videos_to_user_ids
- )
- all_notifs_to_user = notifs_of_albums_to_user.union(notifs_of_videos_to_user)
- return all_notifs_to_user.order_by('-creation_date_time')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement