Browse Source

Arruma convenção de lista e demais sugestões

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/263/head
Luciano Almeida 9 years ago
parent
commit
98c05d21b7
  1. 14
      legacy/migration.py

14
legacy/migration.py

@ -105,8 +105,7 @@ def get_fk_related(field, value, label=None):
warn(msg + ' => using NONE for zero value') warn(msg + ' => using NONE for zero value')
else: else:
value = make_stub(field.related_model, value) value = make_stub(field.related_model, value)
stubs_list.append( stubs_list.append((value.id, field))
(value.id, field.model, field.related_model, field.name))
warn(msg + ' => STUB CREATED') warn(msg + ' => STUB CREATED')
else: else:
assert value assert value
@ -253,16 +252,11 @@ class DataMigrator:
def delete_stubs(self): def delete_stubs(self):
for line in stubs_list: for line in stubs_list:
stub_id = line[0] stub, field = line
model = line[1]
related_model = line[2]
field_name = line[3]
# Filter all objects in model and delete from related model # Filter all objects in model and delete from related model
# if quantity is equal to zero # if quantity is equal to zero
obj_quantity = model.objects.filter(**{field_name: stub_id}) if field.model.objects.filter(**{field.name: stub}).exists():
if obj_quantity.count() == 0: field.related_model.objects.get(**{'id': stub}).delete()
related_model.objects.get(**{'id': stub_id}).delete()
def migrate(obj=appconfs): def migrate(obj=appconfs):

Loading…
Cancel
Save