Add sensor_data app to Django settings and URL routing
- Included sensor_data in the INSTALLED_APPS of settings.py. - Added URL path for sensor_data in urls.py to enable API access.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Management command to seed the 7 initial sensor parameters.
|
||||
Run: python manage.py seed_sensor_parameters
|
||||
"""
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from sensor_data.models import ParameterUpdateLog, SensorParameter
|
||||
|
||||
|
||||
INITIAL_PARAMETERS = [
|
||||
("soil_moisture", "رطوبت خاک", "%"),
|
||||
("soil_temperature", "دما خاک", "°C"),
|
||||
("soil_ph", "pH خاک", ""),
|
||||
("electrical_conductivity", "هدایت الکتریکی", "dS/m"),
|
||||
("nitrogen", "ازت (N)", "mg/kg"),
|
||||
("phosphorus", "فسفر", "mg/kg"),
|
||||
("potassium", "پتاسیم", "mg/kg"),
|
||||
]
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Seed 7 initial sensor parameters (soil_moisture, soil_temperature, etc.)"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
created_count = 0
|
||||
for code, name_fa, unit in INITIAL_PARAMETERS:
|
||||
param, created = SensorParameter.objects.get_or_create(
|
||||
code=code,
|
||||
defaults={"name_fa": name_fa, "unit": unit},
|
||||
)
|
||||
if created:
|
||||
ParameterUpdateLog.objects.create(
|
||||
parameter=param,
|
||||
action="added",
|
||||
)
|
||||
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 parameters.")
|
||||
)
|
||||
Reference in New Issue
Block a user