From 8cd546fef1bcc7d2f71fa5d1e0df47e48741ac88 Mon Sep 17 00:00:00 2001 From: Muhammad Umar Khan Date: Thu, 7 Dec 2023 14:24:52 +0500 Subject: [PATCH] feat: make basket_lineattribute value json compatible --- ...ake_lineattribute_value_json_compatible.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py diff --git a/ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py b/ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py new file mode 100644 index 00000000000..7f328340998 --- /dev/null +++ b/ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from django.core.paginator import Paginator +from django.db import migrations + + +def make_lineattribute_value_json_compatible(apps, schema_editor): + """ + Makes line attribute value json compatible. + """ + LineAttribute = apps.get_model("basket", "LineAttribute") + attributes = LineAttribute.objects.order_by('id') + paginator = Paginator(attributes, 1000) + + for page_number in paginator.page_range: + page = paginator.page(page_number) + updates = [] + + for obj in page.object_list: + obj.value = '"{}"'.format(obj.value) + updates.append(obj) + + LineAttribute.objects.bulk_update(updates, ['value']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('voucher', '0015_add_paymentintentid'), + ] + + operations = [ + migrations.RunPython(make_lineattribute_value_json_compatible, migrations.RunPython.noop), + ]