Increase length of multiple-choice country fields

This commit is contained in:
Raphael Michel
2020-09-09 20:46:24 +02:00
parent d703eeb770
commit 3f4f9d98de

View File

@@ -33,6 +33,15 @@ class CachedCountries(Countries):
class FastCountryField(CountryField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("countries", CachedCountries)
if "max_length" not in kwargs:
# Override logic from CountryField to include 20% buffer. We don't want to migrate our database
# every time a new country is added to the system!
if kwargs.get("multiple", False):
kwargs["max_length"] = int(len(kwargs['countries']()) * 3 * 1.2)
else:
kwargs["max_length"] = 2
super().__init__(*args, **kwargs)
def check(self, **kwargs):