first commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""
|
||||
Management command to seed weather parameters.
|
||||
Run: python manage.py seed_weather_parameters
|
||||
"""
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from weather.models import WeatherParameter
|
||||
|
||||
|
||||
INITIAL_PARAMETERS = [
|
||||
("temperature_min", "حداقل دمای هوا", "°C"),
|
||||
("temperature_max", "حداکثر دمای هوا", "°C"),
|
||||
("temperature_mean", "میانگین دمای هوا", "°C"),
|
||||
("precipitation", "مجموع بارش", "mm"),
|
||||
("precipitation_probability", "احتمال بارش", "%"),
|
||||
("humidity_mean", "میانگین رطوبت نسبی", "%"),
|
||||
("wind_speed_max", "حداکثر سرعت باد", "km/h"),
|
||||
("et0", "تبخیر-تعرق مرجع (ET₀)", "mm/day"),
|
||||
("weather_code", "کد وضعیت آبوهوا (WMO)", ""),
|
||||
]
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Seed weather parameters (temperature, precipitation, ET0, etc.)"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
created_count = 0
|
||||
for code, name_fa, unit in INITIAL_PARAMETERS:
|
||||
_, created = WeatherParameter.objects.get_or_create(
|
||||
code=code,
|
||||
defaults={"name_fa": name_fa, "unit": unit},
|
||||
)
|
||||
if created:
|
||||
created_count += 1
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f" Created: {code} ({name_fa})")
|
||||
)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"\nDone. Created {created_count} new weather parameters."
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user