From 5127590e9334f84a2fd37b1faafcee7c06204656 Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 16 Feb 2016 18:39:45 -0200 Subject: [PATCH] Adiciona script para ajustar campos char vazios --- .../convert_null_to_empty_in_all_char_fields.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scripts/convert_null_to_empty_in_all_char_fields.py diff --git a/scripts/convert_null_to_empty_in_all_char_fields.py b/scripts/convert_null_to_empty_in_all_char_fields.py new file mode 100644 index 000000000..d828a8fd3 --- /dev/null +++ b/scripts/convert_null_to_empty_in_all_char_fields.py @@ -0,0 +1,17 @@ +from sapl.utils import appconfs +from django.db import models + + +def convert_null_to_empty(): + for app in appconfs: + for model in app.get_models(): + print('Convertendo null p/ vazio. model [%s]' + % model._meta.model_name) + char_fields = [f for f in model._meta.fields + if isinstance(f, (models.CharField, + models.TextField))] + for obj in model.objects.all(): + for field in char_fields: + if getattr(obj, field.name) is None: + setattr(obj, field.name, '') + obj.save()