Advertisement
Guest User

Untitled

a guest
Jan 8th, 2021
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1.     def get_queryset(self):
  2.         user = self.request.user
  3.  
  4.         queryset = Notification.objects.annotate(Count('album'), Count('video'))
  5.         notifs_of_albums = queryset.filter(album__count__gte=1)
  6.         notifs_of_videos = queryset.filter(video__count__gte=1)
  7.  
  8.         notifs_of_albums_to_user = notifs_of_albums.filter(
  9.             album__artist__in=Artist.objects.filter(subscriptions__subscriber=user)
  10.         )
  11.         notifs_of_videos_to_user = notifs_of_videos.filter(
  12.             video__channel__in=Channel.objects.filter(subscriptions__subscriber=user)
  13.         )
  14.  
  15.         all_notifs_to_user = notifs_of_albums_to_user | notifs_of_videos_to_user
  16.  
  17.         return all_notifs_to_user.order_by('-creation_date_time')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement