def get_context_data(self, **kwargs): ctx = super(UserManageFollow, self).get_context_data(**kwargs) ctx['list_follow'] = return_list_following_of_user(self.object) ctx['check'] = 'following' for i in ctx['list_follow']: i.count_favorite = return_list_book_favorite(i).count() i.count_reading_book = return_list_book_read(i, 1).count() i.check_follow = False return ctx
def return_list_following_of_user(user): try: following = Follow.objects.filter(follower=user.user_profile).values_list('followee', flat=True) list_user_following = User.objects.filter(user_profile__id__in=following) for i in list_user_following: i.count_favorite = return_list_book_favorite(i).count() i.count_reading_book = return_list_book_read(i, 1).count() i.check_follow = False return list_user_following except: return []
def get_context_data(self, **kwargs): ctx = super(UserHomePage, self).get_context_data(**kwargs) if self.object in return_list_following_of_user(self.request.user) or self.object == self.request.user: search = self.request.GET.get('search', None) count = 6 ctx['check'] = True ctx['count_favorite'] = return_list_book_favorite(self.object).count() ctx['count_reading_book'] = return_list_book_read(self.object, 1).count() ctx['list_book_read'] = return_list_book_read(self.object, 2, count, search) ctx['list_book_reading'] = return_list_book_read(self.object, 1, count, search) ctx['list_book_favorite'] = return_list_book_favorite(self.object, count, search) ctx['list_user_following'] = return_list_following_of_user(self.object) ctx['list_user_followers'] = return_list_followers_of_user(self.object) ctx['list_user_review'] = return_list_review_of_user(self.object) if self.object == self.request.user: ctx['user_profile'] = True else: ctx['check'] = False ctx['count_favorite'] = return_list_book_favorite(self.object).count() ctx['count_reading_book'] = return_list_book_read(self.object, 1).count() return ctx