diff --git a/ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py b/ecommerce/extensions/voucher/migrations/0013_auto_20231115_1047.py similarity index 83% rename from ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py rename to ecommerce/extensions/voucher/migrations/0013_auto_20231115_1047.py index 07e9af22939..89c0f81497d 100644 --- a/ecommerce/extensions/voucher/migrations/0014_auto_20231114_1156.py +++ b/ecommerce/extensions/voucher/migrations/0013_auto_20231115_1047.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.20 on 2023-11-14 11:56 +# Generated by Django 3.2.20 on 2023-11-15 10:47 from django.db import migrations, models @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ('voucher', '0013_make_voucher_names_unique'), + ('voucher', '0012_voucher_is_public'), ] operations = [ @@ -36,11 +36,6 @@ class Migration(migrations.Migration): name='date_created', field=models.DateTimeField(auto_now_add=True, db_index=True), ), - migrations.AlterField( - model_name='voucher', - name='name', - field=models.CharField(help_text='This will be shown in the checkout and basket once the voucher is entered', max_length=128, unique=True, verbose_name='Name'), - ), migrations.AlterField( model_name='voucherapplication', name='date_created', diff --git a/ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py b/ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py deleted file mode 100644 index 2fec782f5da..00000000000 --- a/ecommerce/extensions/voucher/migrations/0013_make_voucher_names_unique.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 3.2.20 on 2023-11-14 11:20 - -from django.core.paginator import Paginator -from django.db import migrations - - -def make_voucher_names_unique(apps, schema_editor): - """ - Appends a number to voucher names. - """ - Voucher = apps.get_model('voucher', 'Voucher') - vouchers = Voucher.objects.order_by('date_created') - paginator = Paginator(vouchers, 1000) - - for page_number in paginator.page_range: - page = paginator.page(page_number) - updates = [] - - for obj in page.object_list: - obj.name = '%d - %s' % (obj.id, obj.name) - updates.append(obj) - - Voucher.objects.bulk_update(updates, ['name']) - - -class Migration(migrations.Migration): - - dependencies = [ - ('voucher', '0012_voucher_is_public'), - ] - - operations = [ - migrations.RunPython(make_voucher_names_unique, migrations.RunPython.noop), - ] diff --git a/ecommerce/extensions/voucher/models.py b/ecommerce/extensions/voucher/models.py index c6b6428bff2..7fa68a8bcd2 100644 --- a/ecommerce/extensions/voucher/models.py +++ b/ecommerce/extensions/voucher/models.py @@ -34,6 +34,15 @@ class OrderLineVouchers(models.Model): class Voucher(AbstractVoucher): + name = models.CharField( + _("Name"), + max_length=128, + help_text=_( + "This will be shown in the checkout" + " and basket once the voucher is" + " entered" + ), + ) SINGLE_USE, MULTI_USE, ONCE_PER_CUSTOMER, MULTI_USE_PER_CUSTOMER = ( 'Single use', 'Multi-use', 'Once per customer', 'Multi-use-per-Customer') USAGE_CHOICES = (