def set_options(self, options):
        """
        options = [{
            'product_option': instance of ProductFinalOption,
            'product_final': instance of ProductFinal,
            'quantity': Float
        }, ]
        """
        with transaction.atomic():
            for option in options:
                opt = self.line_basket_option_sales.filter(
                    product_option=option['product_option']
                ).first()
                if opt:  # edit
                    change = False
                    if opt.quantity != option['quantity']:
                        opt.quantity = option['quantity']
                        change = True
                    if opt.product_final != option['product_final']:
                        opt.product_final = option['product_final']
                        change = True
                    if change:
                        opt.save()
                else:  # new
                    opt = SalesLineBasketOption()
                    # raise Exception(self.pk, self.__dict__, self)
                    # raise Exception(self.pk)
                    opt.line_budget = SalesLineBasket.objects.get(pk=self.pk)
                    opt.product_option = option['product_option']
                    opt.product_final = option['product_final']
                    opt.quantity = option['quantity']
                    opt.save()
def set_options ( self , options ) : with transaction . atomic ( ) : for option in options : opt = self . line_basket_option_sales . filter ( product_option = option [ 'product_option' ] ) . first ( ) if opt : change = False if opt . quantity != option [ 'quantity' ] : opt . quantity = option [ 'quantity' ] change = True if opt . product_final != option [ 'product_final' ] : opt . product_final = option [ 'product_final' ] change = True if change : opt . save ( ) else : opt = SalesLineBasketOption ( ) opt . line_budget = SalesLineBasket . objects . get ( pk = self . pk ) opt . product_option = option [ 'product_option' ] opt . product_final = option [ 'product_final' ] opt . quantity = option [ 'quantity' ] opt . save ( )
options = [{
            'product_option': instance of ProductFinalOption,
            'product_final': instance of ProductFinal,
            'quantity': Float
        }, ]