def list(self, request, *args, **kwargs): try: object_list = self.get_queryset().filter( types__typename=news_type.get('handian_news')) news_list = object_list.order_by('-is_top', '-createtime') # news_list = self.get_queryset().filter(types__typename=news_type.get('handian_news'))[:4] except Exception: news_list = None try: action_list = self.get_queryset().filter( types__typename=news_type.get('same_action'))[:4] except Exception: action_list = None # article_serializer = self.serializer_class(news_list, many=True) handian_news = serializer_function(self, news_list, is_many=True) # news_serializer = self.serializer_class(action_list, many=True) action_news = serializer_function(self, action_list, is_many=True) data = { 'handian_news': handian_news if handian_news else None, 'action_news': action_news if action_news else None } return data
def news(self, request, pk, *args, **kwargs): try: pk_obj = self.get_object() except Exception: pk_obj = None # serializer = self.serializer_class(pk_obj) try: news_obj = pk_obj.get_next_by_create_time() next_news = get_next_news_not_position(news_obj) except Articles.DoesNotExist: next_news = None try: news_obj = pk_obj.get_previous_by_create_time() previous_news = get_pre_news_not_position(news_obj) except Articles.DoesNotExist: previous_news = None data = { 'news': serializer_function(self, pk_obj), 'newsOnenav': True, 'next': next_news, 'previous': previous_news } return data
def list(self, request, *args, **kwargs): data = {} obj_products = self.filter_queryset(self.get_queryset()) # serializer = self.serializer_class(obj_products, many=True) data.update({ 'productnav': True, 'objects': serializer_function(self, obj_products, is_many=True), }) return data
def recruitment(self, request, *args, **kwargs): position_articles = ArticleView.queryset.filter( types__typename=position_type) # serializer_info = ArticleView.serializer_class(position_articles, many=True) serializer_position_society = self.get_serializer( self.get_queryset().filter(types='society'), many=True) serializer_position_student = self.get_serializer( self.get_queryset().filter(types='student'), many=True) return { 'position_info': serializer_function(ArticleView, position_articles, is_many=True), 'position_society': serializer_position_society.data, 'position_student': serializer_position_student.data }