def set_rarity(apps, schema_editor): ITEM_RARITIES = { "Rare": lambda r: r <= 10, "Very Rare": lambda r: 11 <= r <= 20, "Extremely Rare": lambda r: 21 <= r <= 30, "Mega Rare": lambda r: r > 30, } Item = apps.get_model("main_app", "Item") items = Item.objects.all() for item in items: for rarity, condition in ITEM_RARITIES.items(): if condition(item.price): item.rarity = rarity break Item.objects.bulk_update(items, ["rarity"])