Background Management-SPU Management of Commodity Management

Posted by anurag2003 on Wed, 02 Oct 2019 08:13:30 +0200

1. SPU table data acquisition

  • Objective: To display the information of spu table on the page.

  • Operational procedures:

    • 1. Subrouting (meiduo_admin/urls.py)

      • #4,spu management
        router = DefaultRouter()
        router.register(r'goods',spu_views.SPUViewSet,base_name="goods")
        urlpatterns += router.urls
        
        
    • 2. Class view (good/spu_views.py)

      • #1,spu management
        class SPUViewSet(ModelViewSet):
            pagination_class = MyPageNumberPagination
            serializer_class = spu_serializers.SPUSerializer
            queryset = SPU.objects.all()
        
    • 3. Serializers (spu_serializers.py)

      • #1,spu serializer
        class SPUSerializer(serializers.ModelSerializer):
        
            #1. Rewrite brand
            brand = serializers.StringRelatedField(read_only=True)
            brand_id = serializers.IntegerField()
        
            #2. Rewriting Classification
            category1 = serializers.StringRelatedField(read_only=True)
            category1_id = serializers.IntegerField()
        
            category2 = serializers.StringRelatedField(read_only=True)
            category2_id = serializers.IntegerField()
        
            category3 = serializers.StringRelatedField(read_only=True)
            category3_id = serializers.IntegerField()
        
            class Meta:
                model = SPU
                fields = "__all__"
        

2. SPU table to get brand information

  • Purpose: Brand information can be obtained when spu is added.

  • Operational procedures:

    • 1. Subrouting (meiduo_admin/urls.py)

      • url(r'^goods/brands/simple/$',spu_views.SPUBrandSimpleView.as_view())
        
    • 2. Class view (good/spu_views.py)

      • #2,spu,brand acquisition
        class SPUBrandSimpleView(ListAPIView):
            serializer_class = spu_serializers.SPUBrandSimpleSerializer
            queryset = Brand.objects.all()
        
    • 3. Serializers (good/spu_serializers.py)

      • #2,spu,brand serializer
        class SPUBrandSimpleSerializer(serializers.ModelSerializer):
            class Meta:
                model = Brand
                fields = ("id","name")
        
        

3. SPU table to obtain first-level classification information

  • Purpose: First-level categorization can be displayed on spu-added pages.

  • Operational procedures:

    • 1. Subrouting (meiduo_admin/urls.py)

      • url(r'^goods/channel/categories/$',spu_views.SPUCategoryView.as_view()),
        
    • 2. Class view (good/spu_views.py)

      • #3,spu,category classification acquisition
        class SPUCategoryView(ListAPIView):
            serializer_class = spu_serializers.SPUCategorySerializer
            queryset = GoodsCategory.objects.filter(parent__isnull=True)
        
    • 3. Serializers (good/spu_serializers.py)

      • #3,spu,category serializer
        class SPUCategorySerializer(serializers.ModelSerializer):
            class Meta:
                model = GoodsCategory
                fields = ("id","name")
        

4. SPU table to obtain secondary and tertiary classification

  • Purpose: After selecting the parent, query the corresponding subset data

  • Operational procedures:

    • 1. Subrouting (meiduo_admin/urls.py)

      • url(r'^goods/channel/categories/(?P<category_id>\d+)/$',spu_views.SPUSubsCategoryView.as_view()),
        
    • 2. Class view (good/spu_views.py)

      • #4,spu, secondary classification, tertiary classification
        class SPUSubsCategoryView(ListAPIView):
            serializer_class = spu_serializers.SPUCategorySerializer
        
            def get_queryset(self):
                category_id = self.kwargs.get("category_id")
                queryset = GoodsCategory.objects.filter(parent_id=category_id).all()
                return queryset
        

5, debug fdfs upload pictures

  • Objective: to debug fdfs upload pictures through terminal

    • 1. Add the client file to utils

    • 2. Terminal Debugging

      • In [1]: from fdfs_client.client import Fdfs_client                                                                                                                 
        
        In [2]: #1. Create objects                                                                                                                                                
        
        In [3]: client = Fdfs_client('/Users/heJing/Desktop/classes2/day19/meiduo14/meiduo_mall/meiduo_mall/utils/fdfs/client.conf')                                       
        
        In [4]: #2. Upload pictures                                                                                                                                                
        
        In [5]: client.upload_by_filename("/Users/heJing/Desktop/Lessons 2/day19/3_data/Test picture/haha.jpg")                                                                
        getting connection
        <fdfs_client.connection.Connection object at 0x10f8459e8>
        <fdfs_client.fdfs_protol.Tracker_header object at 0x10f845710>
        Out[5]: 
        {'Group name': 'group1',
         'Remote file_id': 'group1/M00/00/03/rBAMhl11zCyAfqwPAACP4XconFQ208.jpg',
         'Status': 'Upload successed.',
         'Local file name': '/Users/heJing/Desktop/Lessons 2/day19/3_data/Test picture/haha.jpg',
         'Uploaded size': '35.00KB',
         'Storage IP': '172.16.12.134'}
        
        

6,spu table uploads pictures

  • AIM: To upload spu images via fdfs

  • Operational procedures:

    • 1. Subrouting (meiduo_admin/urls.py)

      • url(r'^goods/images/$',spu_views.SPUImageUploadView.as_view()),
        
    • 2. Class view (good/spu_views.py)

      • #5,spu,image upload
        class SPUImageUploadView(APIView):
        
            def post(self,request):
                #1. Get the parameters
                image = request.FILES.get("image")
        
                #2. Calibration parameters
                if not image:
                    return Response(status=400)
        
                #3. Data warehousing (fdfs)
                #3,1 Upload Pictures
                client = Fdfs_client(settings.BASE_CONFIG)
                result = client.upload_by_buffer(image.read())
        
                #3,2 Judging whether the picture was uploaded successfully
                if result.get("Status") != "Upload successed.":
                    return Response(status=400)
        
                image_url = result.get("Remote file_id")
        
                #4. Return the response
                return Response({
                    "img_url":"%s%s"%(settings.BASE_URL,image_url)
                })
        

7. SP table data save, update, delete

  • Note: Since the SPU is managed by view set, it has been implemented.