SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ListCreateSKUView(ListCreateAPIView):
  2.     queryset = Sku.objects.all()
  3.     filter_backends = (CustomFilter,)
  4.  
  5.     def get_serializer_class(self):
  6.         if self.request.method == "POST":
  7.             return CreateSkuSerializer
  8.         else:
  9.             return SkuSerializer
  10.  
  11.     def perform_create(self, serializer):
  12.         """
  13.        При создании нового sku, всем записям имеющим такойже
  14.        new_barcode присвается созданное sku.
  15.        """
  16.         with atomic():
  17.             # TODO положить код в сериалайзер
  18.             instance = _save_sku(serializer)
  19.  
  20.             for smd in SkuMonitoringData.objects\
  21.                     .filter(new_barcode=instance.barcode):
  22.                 smd.status = SkuMonitoringData.APPROVED
  23.                 smd.sku = instance
  24.                 process_status(smd)
  25.                 smd.log_new_barcode(self.request.user, instance.barcode)
  26.                 smd.save()
  27.  
  28.  
  29.  
  30.  
  31. class CreateSkuSerializer(serializers.ModelSerializer):
  32.     class Meta:
  33.         model = Sku
  34.         fields = ("barcode", "name", "brand", "producer", "real_producer", "segment", "new_producer", "new_brand")
  35.         read_only_fields = ("new_producer", "new_brand",)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top