-
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.
Merge pull request #968 from maykinmedia/feature/967-clear-toelichtin…
…g-field 🐛 [#967] fixed bug that wouldn't clear toelichting field
- Loading branch information
Showing
2 changed files
with
41 additions
and
27 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
29 changes: 29 additions & 0 deletions
29
src/sdg/producten/migrations/0057_remove_unwanted_toelichting_fields.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,29 @@ | ||
# Generated by Django 3.2.18 on 2023-08-23 21:42 | ||
|
||
from django.db import migrations | ||
from django.db.models import Q | ||
|
||
|
||
def remove_unwanted_toelichting_fields(apps, schema_editor): | ||
LocalizedProducts = apps.get_model("producten", "LocalizedProduct") | ||
for LocalizedProduct in LocalizedProducts.objects.filter( | ||
~Q(product_aanwezig_toelichting__exact="") | ||
): | ||
if ( | ||
LocalizedProduct.product_versie.product.product_aanwezig | ||
or LocalizedProduct.product_versie.product.product_aanwezig is None | ||
): | ||
LocalizedProduct.product_aanwezig_toelichting = "" | ||
LocalizedProduct.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("producten", "0056_remove_localizedgeneriekproduct_slug"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
remove_unwanted_toelichting_fields, migrations.RunPython.noop | ||
), | ||
] |