Skip to content

Commit 26976dc

Browse files
authored
Fixed #1597 -- Hardcoded currency choices in MoneyField
This should prevent spurious migrations being generated when updating django-money or babel.
1 parent d031005 commit 26976dc

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

djangoproject/settings/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@
256256

257257
PUSH_CREDENTIALS = "aggregator.utils.push_credentials"
258258

259+
# django-money settings
260+
261+
CURRENCIES = ("USD",)
262+
259263
# SUPERFEEDR_CREDS is a 2 element list in the form of [email,secretkey]
260264
SUPERFEEDR_CREDS = SECRETS.get("superfeedr_creds")
261265

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generated by Django 4.2.14 on 2024-09-26 11:12
2+
3+
from decimal import Decimal
4+
from django.db import migrations
5+
import djmoney.models.fields
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('foundation', '0005_alter_approvedgrant_amount_currency_and_more'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='approvedgrant',
17+
name='amount',
18+
field=djmoney.models.fields.MoneyField(currency_choices=[('AUD', 'Australian Dollar'), ('EUR', 'Euro'), ('NGN', 'Nigerian Naira'), ('USD', 'US Dollar')], decimal_places=2, default=Decimal('0.0'), default_currency='USD', max_digits=10),
19+
),
20+
migrations.AlterField(
21+
model_name='approvedgrant',
22+
name='amount_currency',
23+
field=djmoney.models.fields.CurrencyField(choices=[('AUD', 'Australian Dollar'), ('EUR', 'Euro'), ('NGN', 'Nigerian Naira'), ('USD', 'US Dollar')], default='USD', editable=False, max_length=3),
24+
),
25+
migrations.AlterField(
26+
model_name='meeting',
27+
name='treasurer_balance_currency',
28+
field=djmoney.models.fields.CurrencyField(choices=[('USD', 'US Dollar')], default='USD', editable=False, max_length=3),
29+
),
30+
]

foundation/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.urls import reverse
66
from django.utils.dateformat import format as date_format
77
from djmoney.models.fields import MoneyField
8+
from djmoney.settings import CURRENCIES
89
from docutils.core import publish_parts
910

1011
from blog.models import BLOG_DOCUTILS_SETTINGS
@@ -131,6 +132,17 @@ class ApprovedGrant(models.Model):
131132
decimal_places=2,
132133
default_currency="USD",
133134
default=Decimal("0.0"),
135+
currency_choices=[
136+
(c.code, c.name)
137+
for i, c in CURRENCIES.items()
138+
if c.code
139+
in {
140+
"USD",
141+
"EUR",
142+
"AUD",
143+
"NGN",
144+
} # This set of currencies was extracted from current usage
145+
],
134146
)
135147
approved_at = models.ForeignKey(
136148
Meeting, related_name="grants_approved", on_delete=models.CASCADE

requirements/common.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Babel==2.10.1
1+
Babel==2.15.0
22
django-contact-form==5.0.1
33
django-countries==7.6.1
44
django-hosts==5.1

0 commit comments

Comments
 (0)