def update_country_preferences(self, country_ids):
        '''Given a list of country IDs, first dedupe and filter out 0s, then
        clear the existing country preferences and construct new ones.'''
        seen = set()
        processed_country_ids = []
        country_preferences = []

        for rank, country_id in enumerate(country_ids):
            if not country_id or country_id in seen:
                continue
            seen.add(country_id)
            processed_country_ids.append(country_id)
            country_preferences.append(
                CountryPreference(
                    school=self,
                    country_id=country_id,
                    rank=rank,
                )
            )

        if country_preferences:
            with transaction.atomic():
                self.countrypreferences.clear()
                CountryPreference.objects.bulk_create(country_preferences)

        return processed_country_ids
dataset/ETHPy150Open bmun/huxley/huxley/core/models.py/School.update_country_preferences/original