Rebuild IPRegion table with fresh data (old ip ranges are removed for simplicity)

def _update_cidr(self, cidr):
        """ Rebuild IPRegion table with fresh data (old ip ranges are removed for simplicity)"""
        new_ip_ranges = []
        is_bulk_create_supported = hasattr(IpRange.objects, 'bulk_create')
        IpRange.objects.all().delete()
        city_region_mapping = self._build_city_region_mapping()

        if self.logger.getEffectiveLevel() in [logging.INFO, logging.DEBUG]:
            pbar = ProgressBar(widgets=[Percentage(), ' ', Bar()])
        else:
            pbar = iter
        for entry in pbar(cidr['cidr']):
            # skipping for country rows
            if entry['city_id']:
                entry.update({'region_id': city_region_mapping[int(entry['city_id'])]})
            if is_bulk_create_supported:
                new_ip_ranges.append(IpRange(**entry))

                if len(new_ip_ranges) >= self.BULK_CHAIN:
                    IpRange.objects.bulk_create(new_ip_ranges)
                    new_ip_ranges = []
            else:
                IpRange.objects.create(**entry)

        if is_bulk_create_supported and new_ip_ranges:
            IpRange.objects.bulk_create(new_ip_ranges)