-
Notifications
You must be signed in to change notification settings - Fork 989
feat: Enhance seed_data command with currency, country, and Faker l…
#664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |||||||
| Usage: | ||||||||
| python manage.py seed_data --email admin@example.com | ||||||||
| python manage.py seed_data --email admin@example.com --orgs 2 --leads 100 --seed 42 | ||||||||
| python manage.py seed_data --email admin@example.com --currency EUR --country DE | ||||||||
| python manage.py seed_data --email admin@example.com --clear --no-input | ||||||||
| """ | ||||||||
|
|
||||||||
|
|
@@ -82,6 +83,24 @@ class Command(BaseCommand): | |||||||
| "Inbound", | ||||||||
| ] | ||||||||
|
|
||||||||
| # Country code to Faker locale mapping | ||||||||
| COUNTRY_FAKER_LOCALES = { | ||||||||
| "US": "en_US", | ||||||||
| "GB": "en_GB", | ||||||||
| "CA": "en_CA", | ||||||||
| "AU": "en_AU", | ||||||||
| "DE": "de_DE", | ||||||||
| "FR": "fr_FR", | ||||||||
| "IN": "en_IN", | ||||||||
| "JP": "ja_JP", | ||||||||
| "CN": "zh_CN", | ||||||||
| "BR": "pt_BR", | ||||||||
| "MX": "es_MX", | ||||||||
| "SG": "en_SG", | ||||||||
| "AE": "ar_AE", | ||||||||
| "CH": "de_CH", | ||||||||
| } | ||||||||
|
|
||||||||
| # Team name templates | ||||||||
| TEAM_NAMES = [ | ||||||||
| ("Sales Team", "Primary sales team handling all inbound leads"), | ||||||||
|
|
@@ -182,6 +201,22 @@ def add_arguments(self, parser): | |||||||
| help="Tags per organization (default: 5)", | ||||||||
| ) | ||||||||
|
|
||||||||
| # Locale options | ||||||||
| valid_currencies = [c[0] for c in CURRENCY_CODES] | ||||||||
| parser.add_argument( | ||||||||
| "--currency", | ||||||||
| type=str, | ||||||||
| default="USD", | ||||||||
| choices=valid_currencies, | ||||||||
| help=f"Default currency for organizations (default: USD). Choices: {', '.join(valid_currencies)}", | ||||||||
| ) | ||||||||
| parser.add_argument( | ||||||||
| "--country", | ||||||||
| type=str, | ||||||||
| default="US", | ||||||||
| help="Default country code for organizations (default: US). Examples: US, GB, CA, AU, DE, FR, IN", | ||||||||
| ) | ||||||||
|
|
||||||||
| # Invoice-related arguments | ||||||||
| parser.add_argument( | ||||||||
| "--products", | ||||||||
|
|
@@ -238,19 +273,25 @@ def add_arguments(self, parser): | |||||||
| ) | ||||||||
|
|
||||||||
| def handle(self, *args, **options): | ||||||||
| # Initialize Faker | ||||||||
| # Initialize Faker with locale matching the country | ||||||||
| country = options["country"].upper() | ||||||||
|
||||||||
| country = options["country"].upper() | |
| country = options["country"].upper() | |
| options["country"] = country |
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if seed: treats 0 as “no seed”, so --seed 0 won’t actually seed random/Faker and will produce non-deterministic results. Use an explicit None check (e.g., if seed is not None:) so all integer seeds work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--countryaccepts any string, butOrg.default_countryis aCharField(max_length=2, choices=COUNTRIES). Passing a value longer than 2 characters (or not in the allowed choices) will raise a DB error duringOrg.objects.create(...)or create inconsistent seed data. Consider constraining the argument (choices and/or length validation) and normalizing to uppercase at parse-time.