Fix CSV upload for Location2025
This commit is contained in:
@ -1201,9 +1201,26 @@ class Location2025(models.Model):
|
||||
|
||||
for row_num, row in enumerate(csv_reader, start=2):
|
||||
try:
|
||||
cp_number = int(row.get('cp_number', 0))
|
||||
if cp_number <= 0:
|
||||
errors.append(f"行{row_num}: CP番号が無効です")
|
||||
# cp列から番号を抽出 (例: "#1(5)" -> 1, "-2" -> -2)
|
||||
cp_raw = row.get('cp', row.get('cp_number', ''))
|
||||
cp_number = None
|
||||
|
||||
if cp_raw:
|
||||
import re
|
||||
# #で始まる場合は#の後の数字を抽出 (例: "#1(5)" -> "1")
|
||||
if cp_raw.startswith('#'):
|
||||
match = re.search(r'#(-?\d+)', str(cp_raw))
|
||||
if match:
|
||||
cp_number = int(match.group(1))
|
||||
else:
|
||||
# 直接数値の場合
|
||||
try:
|
||||
cp_number = int(cp_raw)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
if cp_number is None:
|
||||
errors.append(f"行{row_num}: CP番号が無効です (値: {cp_raw})")
|
||||
continue
|
||||
|
||||
# 緯度経度から位置情報を作成
|
||||
@ -1221,7 +1238,7 @@ class Location2025(models.Model):
|
||||
|
||||
defaults = {
|
||||
# 基本フィールド
|
||||
'cp_name': row.get('cp_name', f'CP{cp_number}'),
|
||||
'cp_name': row.get('loc_name', row.get('cp_name', f'CP{cp_number}')),
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'location': location,
|
||||
@ -1229,11 +1246,11 @@ class Location2025(models.Model):
|
||||
'buy_point': int(row.get('buy_point', 0)),
|
||||
'address': row.get('address', ''),
|
||||
'phone': row.get('phone', ''),
|
||||
'description': row.get('description', ''),
|
||||
'description': row.get('description', row.get('remark', '')),
|
||||
|
||||
# 新しいフィールド
|
||||
'sub_loc_id': row.get('sub_loc_id', ''),
|
||||
'subcategory': row.get('subcategory', ''),
|
||||
'subcategory': row.get('subcategory', row.get('category', '')),
|
||||
'photos': row.get('photos', ''),
|
||||
'videos': row.get('videos', ''),
|
||||
'tags': row.get('tags', ''),
|
||||
|
||||
Reference in New Issue
Block a user