Fix API and admin for location2025

This commit is contained in:
2025-08-30 04:12:55 +09:00
parent 596b7313dd
commit cb399f14bf
3 changed files with 139 additions and 14 deletions

View File

@ -36,17 +36,85 @@ class LocationCatSerializer(serializers.ModelSerializer):
fields=['category',]
class LocationSerializer(GeoFeatureModelSerializer):
class LocationSerializer(serializers.ModelSerializer):
# evaluation_valueに基づくインタラクション情報を追加
interaction_type = serializers.SerializerMethodField()
requires_photo = serializers.SerializerMethodField()
requires_qr_code = serializers.SerializerMethodField()
interaction_instructions = serializers.SerializerMethodField()
# 追加フィールドのカスタムシリアライズ
has_photos = serializers.SerializerMethodField()
has_videos = serializers.SerializerMethodField()
photos_list = serializers.SerializerMethodField()
videos_list = serializers.SerializerMethodField()
tags_list = serializers.SerializerMethodField()
# 位置情報の緯度経度
latitude_float = serializers.SerializerMethodField()
longitude_float = serializers.SerializerMethodField()
class Meta:
model=Location2025
geo_field='geom'
fields="__all__"
fields=[
# 基本フィールド
'id', 'cp_number', 'event', 'cp_name', 'sub_loc_id', 'subcategory',
'latitude', 'longitude', 'location', 'address',
'cp_point', 'photo_point', 'buy_point',
'checkin_radius', 'auto_checkin',
'shop_closed', 'shop_shutdown', 'opening_hours',
'phone', 'website', 'description', 'remark',
# 追加フィールド
'photos', 'videos', 'tags', 'evaluation_value', 'hidden_location',
# 管理フィールド
'is_active', 'sort_order', 'csv_source_file', 'csv_upload_date',
'created_at', 'updated_at', 'created_by', 'updated_by',
# カスタムフィールド
'interaction_type', 'requires_photo', 'requires_qr_code', 'interaction_instructions',
'has_photos', 'has_videos', 'photos_list', 'videos_list', 'tags_list',
'latitude_float', 'longitude_float'
]
def get_latitude_float(self, obj):
"""位置情報から緯度を取得"""
if obj.location:
return obj.location.y
return obj.latitude
def get_longitude_float(self, obj):
"""位置情報から経度を取得"""
if obj.location:
return obj.location.x
return obj.longitude
def get_has_photos(self, obj):
"""写真データの有無を返す"""
return bool(obj.photos and obj.photos.strip())
def get_has_videos(self, obj):
"""動画データの有無を返す"""
return bool(obj.videos and obj.videos.strip())
def get_photos_list(self, obj):
"""写真ファイル名をリストで返す"""
if not obj.photos or not obj.photos.strip():
return []
# カンマ区切りで分割してリストとして返す
return [photo.strip() for photo in obj.photos.split(',') if photo.strip()]
def get_videos_list(self, obj):
"""動画ファイル名をリストで返す"""
if not obj.videos or not obj.videos.strip():
return []
# カンマ区切りで分割してリストとして返す
return [video.strip() for video in obj.videos.split(',') if video.strip()]
def get_tags_list(self, obj):
"""タグをリストで返す"""
if not obj.tags or not obj.tags.strip():
return []
# カンマ区切りで分割してリストとして返す
return [tag.strip() for tag in obj.tags.split(',') if tag.strip()]
def get_interaction_type(self, obj):
"""evaluation_valueに基づくインタラクションタイプを返す"""