実装内容 バグ修正 - fields/views.py: OfficialChusakanField → OfficialChusankanField init_crops コマンド ✅ python manage.py init_crops 水稲: 5 varieties 大豆: 3 varieties 小麦: 2 varieties そば: 2 varieties とうきび: 1 varieties serializers.py - CropSerializer - 作物マスタ - VarietySerializer - 品種マスタ - PlanSerializer - 作付け計画(crop_name, variety_name, field_name 付き) views.py - CropViewSet, VarietyViewSet, PlanViewSet - アクション: summary, copy_from_previous_year, get_crops_with_varieties API エンドポイント - /api/plans/crops/ - 作物一覧 - /api/plans/varieties/ - 品種一覧 - /api/plans/ - 作付け計画CRUD - /api/plans/summary/?year=2025 - 集計 テスト結果 GET /api/plans/crops/ → ✅ GET /api/plans/ → ✅ (空配列)
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from django.core.management.base import BaseCommand
|
|
from apps.plans.models import Crop, Variety
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Initialize crops and varieties master data'
|
|
|
|
def handle(self, *args, **options):
|
|
crops_data = [
|
|
{
|
|
'name': '水稲',
|
|
'varieties': ['コシヒカリ', 'ひとめぼれ', 'あきたこまち', 'つや姫', 'oniai']
|
|
},
|
|
{
|
|
'name': '大豆',
|
|
'varieties': ['タマホマレ', 'エンレイ', 'ミヤギром']
|
|
},
|
|
{
|
|
'name': '小麦',
|
|
'varieties': ['キタノカオリ', 'ホウライ']
|
|
},
|
|
{
|
|
'name': 'そば',
|
|
'varieties': ['信濃一号', 'はるか']
|
|
},
|
|
{
|
|
'name': 'とうきび',
|
|
'varieties': ['ゴールdent']
|
|
},
|
|
]
|
|
|
|
for crop_data in crops_data:
|
|
crop, _ = Crop.objects.get_or_create(name=crop_data['name'])
|
|
for variety_name in crop_data['varieties']:
|
|
Variety.objects.get_or_create(crop=crop, name=variety_name)
|
|
self.stdout.write(f'{crop.name}: {len(crop_data["varieties"])} varieties')
|
|
|
|
self.stdout.write(self.style.SUCCESS('Successfully initialized crops and varieties'))
|