1. Obtain advertising and store a list of published
1. Write the ad or get a list of stores like GetPubGoods published in apps / ad / views.py in:
class GetPubGoods (APIView): "" " Get the creative shop or a list of published " "" renderer_classes = [JSONRenderer] # renderer DEF GET (Self, Request): Page = request.GET.get ( ' Page ' ) Sheng = request.GET.get ( ' Sheng ' ) Shi = request.GET.get ( ' Shi ' ) Xian = request.GET.get ( ' Xian ' ) Tab = request.GET.get ( ' Tab ' ) tab1 = request.GET.get('tab1') if page and tab and tab1 and xian and shi and sheng: # print(page,sheng,shi,xian,tab,tab1) page=int(page) tab=int(tab) tab1=int(tab1) fenlei_id=request.GET.get('fenleiid') if fenlei_id: # 分类页面发来的请求 fenlei_id=int(fenlei_id) category=Category.objects.filter(id=fenlei_id).first() if tab1 == 1: # 全省 num = Area.objects.filter(name=sheng).first().num # print(num) re_list = Good.objects.filter(area__num__gt=num, area__num__lt=(num + 10000), stage=2, type=tab,category=category).order_by('-last_visit_time')[0:(5 * page)] re GoodModelSerializer = (re_list, MANY =True) image_list = [] IMG = {} for ITEM1 in re_list: first_img = Images.objects.filter (Good = ITEM1) .first () IMG [ ' ID ' ] = item1.id IMG [ ' Image ' ] = the HOST + STR ( first_img.image) image_list.append (img) img = {} # this phrase, the last picture in the list of all the elements will be the last time img assignment content return the Response (the Data = ({'good': re.data, 'image_list': image_list})) elif tab1 == 2: # 全市 num = Area.objects.filter(name=shi).first().num # print(num) re_list = Good.objects.filter(area__num__gte=num, area__num__lt=(num + 100), stage=2, type=tab,category=category).order_by('-last_visit_time')[0:(5 * page)] re = GoodModelSerializer(re_list, many=True) image_list = [] IMG = {} for ITEM1 in re_list: first_img = Images.objects.filter (Good = ITEM1) .first () IMG [ ' ID ' ] = item1.id IMG [ ' Image ' ] + = the HOST str (first_img.image) image_list.append (img) img = {} # this phrase, the last picture in the list of all the elements will be the last time img assignment content return the Response (Data = ({ ' Good ' : re.data, ' image_list ' : image_list})) elif TAB1 ==. 3 : # county Area.objects.filter = NUM (name = Xian) .first (). NUM # Print (NUM) re_list = Good.objects.filter (NUM = area__num, Stage 2 =, = Tab type, category = category) .order_by ( ' -last_visit_time ' ) [ 0 :( . 5 * Page)] ReGoodModelSerializer = (re_list, MANY =True) image_list = [] IMG = {} for ITEM1 in re_list: first_img = Images.objects.filter (Good = ITEM1) .first () IMG [ ' ID ' ] = item1.id IMG [ ' Image ' ] = the HOST + STR ( first_img.image) image_list.append (img) img = {} # this phrase, the last picture in the list of all the elements will be the last time img assignment content return the Response (the Data = ({' Good ' : re.data, ' image_list ' : image_list})) the else : return the HttpResponse ( ' TAB1 parameter error ' ) the else : # Home initiated request IF TAB1. 1 == : # province num = Area.objects.filter (name = Sheng) .first (). NUM # Print (NUM) re_list = Good.objects.filter (NUM = area__num__gt, area__num__lt = (10000 + NUM), Stage = 2, type = Tab) .order_by ( ' -last_visit_time')[0:(5 * page)] re = GoodModelSerializer(re_list, many=True) image_list=[] img={} for item1 in re_list: first_img=Images.objects.filter(good=item1).first() img['id'] = item1.id img['image'] = HOST + str(first_img.image) image_list.append (img) img Page)]= {} # This phrase, the last picture in the list of all the elements will be the last time img assignment content return the Response (the Data = ({ ' Good ' : re.data, ' image_list ' : image_list})) elif tab1 == 2 : # city NUM = Area.objects.filter (name = . Shi) .first () NUM # Print (NUM) re_list = Good.objects.filter (NUM = area__num__gte, area__num__lt = (NUM + 100), Stage 2 = , type = Tab) .order_by ( ' -last_visit_time ' ) [0: (. 5 * Re = GoodModelSerializer (re_list, MANY =True) image_list = [] IMG = {} for ITEM1 in re_list: first_img = Images.objects.filter (Good = ITEM1) .first () IMG [ ' ID ' ] = item1.id IMG [ ' Image ' ] + = the HOST str (first_img.image) image_list.append (img) img = {} # this phrase, the last picture in the list of all the elements will be the last time img assignment content return Response(data=({'good': re.data, 'image_list': image_list})) elif tab1==3: #全县 num = Area.objects.filter(name=xian).first().num # print(num) re_list = Good.objects.filter(area__num=num, stage=2,type=tab).order_by('-last_visit_time')[0:(5 * page)] re = GoodModelSerializer(re_list, many=True) image_list = [] IMG = {} for ITEM1 in re_list: first_img = Images.objects.filter (Good = ITEM1) .first () IMG [ ' ID ' ] = item1.id IMG [ ' Image ' ] = the HOST + STR (first_img.image) image_list.append (img) img = {} # this phrase, the final picture will be the list of all the elements of the last assignment content img return the Response (Data = ({ ' Good ' : re.data, 'image_list ': Image_list})) the else : return the HttpResponse ( ' TAB1 parameter error ' ) the else : return the HttpResponse ( ' parameter less than ' )
Configuring routing apps / ad / urls.py of:
from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetGoods,GetImgs,GetPubGoods urlpatterns = [ path('getcategory/',GetCategory.as_view()), path('createadorshop/',CreateAdOrShop.as_view()), path('uploadimg/',UpLoadImg.as_view()), path('getgoods/',GetGoods.as_view()), path('getimgs/',GetImgs.as_view()), path('getpubgoods/',GetPubGoods.as_view()), ]
2. Obtain and store details of the ad published
1. Get the creative writing class GetGoodDesc details or shop in apps / ad / views.py in:
class GetGoodDesc(APIView): """获取广告或店铺详情""" renderer_classes = [JSONRenderer] # 渲染器 def get(self,request): good_id=request.GET.get('goodid') if good_id: good_id=int(good_id) good=Good.objects.filter(id=good_id).first() re_good=GoodModelSerializer(good) img_obj_list=Images.objects.filter(good=good) img_list=[] for item in img_obj_list: img_list.append(HOST+str(item.image)) return Response(data=({'good':re_good.data,'image_list':img_list})) return HttpResponse('未收到id')
2. Write route apps / ad / urls.py in:
from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetGoods,GetImgs,GetPubGoods,GetGoodDesc urlpatterns = [ path('getcategory/',GetCategory.as_view()), path('createadorshop/',CreateAdOrShop.as_view()), path('uploadimg/',UpLoadImg.as_view()), path('getgoods/',GetGoods.as_view()), path('getimgs/',GetImgs.as_view()), path('getpubgoods/',GetPubGoods.as_view()), path('getgooddesc/',GetGoodDesc.as_view()), ]