修正完了
backend/apps/fields/views.py を修正しました: 修正内容 1. 共済マスタ取込 (import_kyosai_master) - k_num → 耕地番号 - s_num → 分筆番号 - address → 地名 地番 - kanji_name → 漢字地名 - area → 本地面積(m2) 2. 実圃場データ取込 (import_yoshida_fields) - name → 名称 - address → 住所 - area_tan → 面積(反) - area_m2 → 面積(反) * 1000 (自動計算) - owner_name → 地主 - raw_kyosai_k_num → 細目_耕地番号 - raw_kyosai_s_num → 細目_分筆番号 - raw_chusankan_id → 中山間_ID 3. 追加した堅牢化 - df.columns = df.columns.str.strip() でカラム名の余白を除去 バックエンドを再起動しました。再度インポートを実行してみてください。
This commit is contained in:
@@ -24,22 +24,23 @@ def import_kyosai_master(request):
|
||||
|
||||
try:
|
||||
df = pd.read_excel(ods_file, engine='odf')
|
||||
df.columns = df.columns.str.strip()
|
||||
|
||||
created_count = 0
|
||||
updated_count = 0
|
||||
|
||||
for _, row in df.iterrows():
|
||||
k_num = str(row.get('k_num', '')).strip() if pd.notna(row.get('k_num')) else ''
|
||||
s_num = str(row.get('s_num', '')).strip() if pd.notna(row.get('s_num')) else ''
|
||||
k_num = str(row.get('耕地番号', '')).strip() if pd.notna(row.get('耕地番号')) else ''
|
||||
s_num = str(row.get('分筆番号', '')).strip() if pd.notna(row.get('分筆番号')) else ''
|
||||
|
||||
if not k_num:
|
||||
continue
|
||||
|
||||
defaults = {
|
||||
's_num': s_num,
|
||||
'address': str(row.get('address', '')).strip() if pd.notna(row.get('address')) else '',
|
||||
'kanji_name': str(row.get('kanji_name', '')).strip() if pd.notna(row.get('kanji_name')) else '',
|
||||
'area': float(row.get('area', 0)) if pd.notna(row.get('area')) else 0,
|
||||
'address': str(row.get('地名 地番', '')).strip() if pd.notna(row.get('地名 地番')) else '',
|
||||
'kanji_name': str(row.get('漢字地名', '')).strip() if pd.notna(row.get('漢字地名')) else '',
|
||||
'area': float(row.get('本地面積(m2)', 0)) if pd.notna(row.get('本地面積(m2)')) else 0,
|
||||
}
|
||||
|
||||
obj, created = OfficialKyosaiField.objects.update_or_create(
|
||||
@@ -73,28 +74,29 @@ def import_yoshida_fields(request):
|
||||
|
||||
try:
|
||||
df = pd.read_excel(ods_file, engine='odf')
|
||||
df.columns = df.columns.str.strip()
|
||||
|
||||
created_count = 0
|
||||
updated_count = 0
|
||||
|
||||
for _, row in df.iterrows():
|
||||
name = str(row.get('name', '')).strip() if pd.notna(row.get('name')) else ''
|
||||
name = str(row.get('名称', '')).strip() if pd.notna(row.get('名称')) else ''
|
||||
|
||||
if not name:
|
||||
continue
|
||||
|
||||
raw_kyosai_k = str(int(row.get('raw_kyosai_k_num', 0))) if pd.notna(row.get('raw_kyosai_k_num')) else None
|
||||
raw_kyosai_s = str(int(row.get('raw_kyosai_s_num', 0))) if pd.notna(row.get('raw_kyosai_s_num')) else None
|
||||
raw_chusankan = str(int(row.get('raw_chusankan_id', 0))) if pd.notna(row.get('raw_chusankan_id')) else None
|
||||
raw_kyosai_k = str(int(row.get('細目_耕地番号', 0))) if pd.notna(row.get('細目_耕地番号')) else None
|
||||
raw_kyosai_s = str(int(row.get('細目_分筆番号', 0))) if pd.notna(row.get('細目_分筆番号')) else None
|
||||
raw_chusankan = str(int(row.get('中山間_ID', 0))) if pd.notna(row.get('中山間_ID')) else None
|
||||
|
||||
area_tan = float(row.get('area_tan', 0)) if pd.notna(row.get('area_tan')) else 0
|
||||
area_m2 = int(row.get('area_m2', 0)) if pd.notna(row.get('area_m2')) else 0
|
||||
area_tan = float(row.get('面積(反)', 0)) if pd.notna(row.get('面積(反)')) else 0
|
||||
area_m2 = int(area_tan * 1000) if area_tan else 0
|
||||
|
||||
defaults = {
|
||||
'address': str(row.get('address', '')).strip() if pd.notna(row.get('address')) else '',
|
||||
'address': str(row.get('住所', '')).strip() if pd.notna(row.get('住所')) else '',
|
||||
'area_tan': area_tan,
|
||||
'area_m2': area_m2,
|
||||
'owner_name': str(row.get('owner_name', '')).strip() if pd.notna(row.get('owner_name')) else '',
|
||||
'owner_name': str(row.get('地主', '')).strip() if pd.notna(row.get('地主')) else '',
|
||||
'raw_kyosai_k_num': raw_kyosai_k,
|
||||
'raw_kyosai_s_num': raw_kyosai_s,
|
||||
'raw_chusankan_id': raw_chusankan,
|
||||
|
||||
Reference in New Issue
Block a user