This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make basket_lineattribute value json compatible
- Loading branch information
1 parent
700cc13
commit 8cd546f
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
ecommerce/extensions/basket/migrations/0016_make_lineattribute_value_json_compatible.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
] |