Simpler migration revert

This commit is contained in:
Ludovic Stephan 2017-03-26 15:06:45 -03:00
parent 06a89055c4
commit 946182f1fe

View file

@ -13,11 +13,9 @@ def adapt_operation_types(apps, schema_editor):
def revert_operation_types(apps, schema_editor):
Operation = apps.get_model("kfet", "Operation")
for ope in Operation.objects.filter(type='edit'):
ope.type = 'deposit' if ope.amount > 0 else 'withdraw'
ope.is_checkout = False
ope.save()
edits = Operation.objects.filter(type='edit')
edits.filter(amount__gt=0).update(type='deposit')
edits.filter(amount__lte=0).update(type='withdraw')
class Migration(migrations.Migration):