-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
305ca28
commit 4b4f566
Showing
2 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
shopelectro/migrations/0026_remove_product_duplications.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,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10 on 2018-08-24 08:44 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def migrate_forward(apps, schema_editor): | ||
Product = apps.get_model('shopelectro', 'Product') | ||
|
||
uuids_to_delete = [ | ||
result['uuid'] for result in | ||
Product.objects.values('uuid').annotate(models.Count('uuid')) | ||
.order_by().filter(uuid__count__gt=1) | ||
] | ||
|
||
preserved = set() | ||
|
||
for product in Product.objects.filter(uuid__in=uuids_to_delete): | ||
if product.uuid in preserved: | ||
product.delete() | ||
else: | ||
preserved.add(product.uuid) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('shopelectro', '0025_tag_unique_constraint'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(migrate_forward), | ||
] |