Skip to content

Commit 9f761fd

Browse files
Update README and refactor model fields for improved clarity and compatibility (#305)
- Updated README to reflect new Python and Django version requirements (Python >= 3.10, Django >= 4.2). - Added instructions for generating translations in the README. - Refactored model fields in abstract_models.py to include verbose names for better clarity in the admin interface. - Created a new migration to apply changes to the database schema, ensuring consistency with updated model definitions.
1 parent bcc6c56 commit 9f761fd

3 files changed

Lines changed: 495 additions & 30 deletions

File tree

README.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,10 @@ database, you should use
2727

2828
Requirements:
2929

30-
- Python >= 3.8
31-
- Django >= 3.2
30+
- Python >= 3.10
31+
- Django >= 4.2
3232
- MySQL or PostgreSQL or SQLite.
3333

34-
Yes, for some reason, code that used to work on MySQL (not without pain xD)
35-
does not work anymore. So we're now using django.db.transaction.atomic which
36-
comes from Django 1.6 just to support MySQL quacks.
37-
3834
Features
3935
--------
4036
- GraphQL support
@@ -169,6 +165,14 @@ To run it even faster, you can switch to specific tox virtualenv::
169165
CI=True py.test -v --cov cities_light --create-db --strict -r fEsxXw cities_light/tests/test_form.py::FormTestCase::testCountryFormNameAndContinentAlone
170166
CI=true test_project/manage.py test cities_light.tests.test_form.FormTestCase.testCountryFormNameAndContinentAlone
171167

168+
169+
If you want to generate the translations, use the following steps::
170+
171+
source .tox/dev/bin/activate
172+
cd src/cities_light
173+
python manage.py makemessages -l fr
174+
python manage.py compilemessages
175+
172176
If you want to build the docs, use the following steps::
173177

174178
source .tox/dev/bin/activate

src/cities_light/abstract_models.py

Lines changed: 95 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ class Base(models.Model):
8383
Base model with boilerplate for all models.
8484
"""
8585

86-
name = models.CharField(max_length=200, db_index=True)
87-
name_ascii = models.CharField(max_length=200, blank=True, db_index=True)
88-
slug = autoslug.AutoSlugField(populate_from="name_ascii")
89-
geoname_id = models.IntegerField(null=True, blank=True, unique=True)
90-
alternate_names = models.TextField(null=True, blank=True, default="")
91-
translations = models.JSONField(default=dict, blank=True)
86+
name = models.CharField(max_length=200, db_index=True, verbose_name=_("name"))
87+
name_ascii = models.CharField(
88+
max_length=200, blank=True, db_index=True, verbose_name=_("ASCII name")
89+
)
90+
slug = autoslug.AutoSlugField(populate_from="name_ascii", verbose_name=_("slug"))
91+
geoname_id = models.IntegerField(
92+
null=True, blank=True, unique=True, verbose_name=_("Geonames ID")
93+
)
94+
alternate_names = models.TextField(
95+
null=True, blank=True, default="", verbose_name=_("alternate names")
96+
)
97+
translations = models.JSONField(
98+
default=dict, blank=True, verbose_name=_("translations")
99+
)
92100

93101
objects = BaseManager()
94102

@@ -111,11 +119,32 @@ class AbstractCountry(Base):
111119
Base Country model.
112120
"""
113121

114-
code2 = models.CharField(max_length=2, null=True, blank=True, unique=True)
115-
code3 = models.CharField(max_length=3, null=True, blank=True, unique=True)
116-
continent = models.CharField(max_length=2, db_index=True, choices=CONTINENT_CHOICES)
117-
tld = models.CharField(max_length=5, blank=True, db_index=True)
118-
phone = models.CharField(max_length=20, null=True, blank=True)
122+
code2 = models.CharField(
123+
max_length=2,
124+
null=True,
125+
blank=True,
126+
unique=True,
127+
verbose_name=_("ISO 3166-1 alpha-2"),
128+
)
129+
code3 = models.CharField(
130+
max_length=3,
131+
null=True,
132+
blank=True,
133+
unique=True,
134+
verbose_name=_("ISO 3166-1 alpha-3"),
135+
)
136+
continent = models.CharField(
137+
max_length=2,
138+
db_index=True,
139+
choices=CONTINENT_CHOICES,
140+
verbose_name=_("continent"),
141+
)
142+
tld = models.CharField(
143+
max_length=5, blank=True, db_index=True, verbose_name=_("top-level domain")
144+
)
145+
phone = models.CharField(
146+
max_length=20, null=True, blank=True, verbose_name=_("phone code")
147+
)
119148

120149
class Meta(Base.Meta):
121150
verbose_name_plural = _("countries")
@@ -127,11 +156,19 @@ class AbstractRegion(Base):
127156
Base Region/State model.
128157
"""
129158

130-
display_name = models.CharField(max_length=200)
131-
geoname_code = models.CharField(max_length=50, null=True, blank=True, db_index=True)
159+
display_name = models.CharField(max_length=200, verbose_name=_("display name"))
160+
geoname_code = models.CharField(
161+
max_length=50,
162+
null=True,
163+
blank=True,
164+
db_index=True,
165+
verbose_name=_("Geonames code"),
166+
)
132167

133168
country = models.ForeignKey(
134-
CITIES_LIGHT_APP_NAME + ".Country", on_delete=models.CASCADE
169+
CITIES_LIGHT_APP_NAME + ".Country",
170+
on_delete=models.CASCADE,
171+
verbose_name=_("country"),
135172
)
136173

137174
class Meta(Base.Meta):
@@ -149,17 +186,26 @@ class AbstractSubRegion(Base):
149186
Base SubRegion model.
150187
"""
151188

152-
display_name = models.CharField(max_length=200)
153-
geoname_code = models.CharField(max_length=50, null=True, blank=True, db_index=True)
189+
display_name = models.CharField(max_length=200, verbose_name=_("display name"))
190+
geoname_code = models.CharField(
191+
max_length=50,
192+
null=True,
193+
blank=True,
194+
db_index=True,
195+
verbose_name=_("Geonames code"),
196+
)
154197

155198
country = models.ForeignKey(
156-
CITIES_LIGHT_APP_NAME + ".Country", on_delete=models.CASCADE
199+
CITIES_LIGHT_APP_NAME + ".Country",
200+
on_delete=models.CASCADE,
201+
verbose_name=_("country"),
157202
)
158203
region = models.ForeignKey(
159204
CITIES_LIGHT_APP_NAME + ".Region",
160205
null=True,
161206
blank=True,
162207
on_delete=models.CASCADE,
208+
verbose_name=_("region"),
163209
)
164210

165211
class Meta(Base.Meta):
@@ -176,43 +222,68 @@ class AbstractCity(Base):
176222
Base City model.
177223
"""
178224

179-
display_name = models.CharField(max_length=200)
225+
display_name = models.CharField(max_length=200, verbose_name=_("display name"))
180226

181227
search_names = ToSearchTextField(
182-
max_length=4000, db_index=INDEX_SEARCH_NAMES, blank=True, default=""
228+
max_length=4000,
229+
db_index=INDEX_SEARCH_NAMES,
230+
blank=True,
231+
default="",
232+
verbose_name=_("search names"),
183233
)
184234

185235
latitude = models.DecimalField(
186-
max_digits=8, decimal_places=5, null=True, blank=True
236+
max_digits=8,
237+
decimal_places=5,
238+
null=True,
239+
blank=True,
240+
verbose_name=_("latitude"),
187241
)
188242

189243
longitude = models.DecimalField(
190-
max_digits=8, decimal_places=5, null=True, blank=True
244+
max_digits=8,
245+
decimal_places=5,
246+
null=True,
247+
blank=True,
248+
verbose_name=_("longitude"),
191249
)
192250

193251
subregion = models.ForeignKey(
194252
CITIES_LIGHT_APP_NAME + ".SubRegion",
195253
blank=True,
196254
null=True,
197255
on_delete=models.CASCADE,
256+
verbose_name=_("subregion"),
198257
)
199258
region = models.ForeignKey(
200259
CITIES_LIGHT_APP_NAME + ".Region",
201260
blank=True,
202261
null=True,
203262
on_delete=models.CASCADE,
263+
verbose_name=_("region"),
204264
)
205265
country = models.ForeignKey(
206-
CITIES_LIGHT_APP_NAME + ".Country", on_delete=models.CASCADE
266+
CITIES_LIGHT_APP_NAME + ".Country",
267+
on_delete=models.CASCADE,
268+
verbose_name=_("country"),
269+
)
270+
population = models.BigIntegerField(
271+
null=True, blank=True, db_index=True, verbose_name=_("population")
272+
)
273+
feature_code = models.CharField(
274+
max_length=10,
275+
null=True,
276+
blank=True,
277+
db_index=True,
278+
verbose_name=_("feature code"),
207279
)
208-
population = models.BigIntegerField(null=True, blank=True, db_index=True)
209-
feature_code = models.CharField(max_length=10, null=True, blank=True, db_index=True)
210280
timezone = models.CharField(
211281
max_length=40,
212282
blank=True,
213283
null=True,
214284
db_index=True,
215285
validators=[timezone_validator],
286+
verbose_name=_("timezone"),
216287
)
217288

218289
class Meta(Base.Meta):

0 commit comments

Comments
 (0)