API: Expose TaxRule.custom_rules (#3426)

This commit is contained in:
Raphael Michel
2023-06-27 13:05:54 +02:00
committed by GitHub
parent 6d604889f2
commit 0f9ec8beca
7 changed files with 136 additions and 17 deletions

View File

@@ -19,6 +19,8 @@
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
import json
from rest_framework import serializers
@@ -46,3 +48,16 @@ class AsymmetricField(serializers.Field):
def run_validation(self, data=serializers.empty):
return self.write.run_validation(data)
class CompatibleJSONField(serializers.JSONField):
def to_internal_value(self, data):
try:
return json.dumps(data)
except (TypeError, ValueError):
self.fail('invalid')
def to_representation(self, value):
if value:
return json.loads(value)
return value