def add_word_count(apps, schema_editor): Entity = apps.get_model("base", "Entity") entities = [] for e in Entity.objects.all(): e.word_count = get_word_count(e.string) entities.append(e) bulk_update(entities, update_fields=["word_count"], batch_size=1000)
def test_get_word_count(input, expected_count): """ How many words are in given strings """ assert get_word_count(input) == expected_count