Fix Postgres error

This commit is contained in:
2025-08-31 10:01:42 +09:00
parent 0ef0bde5b1
commit 71b073229e
3 changed files with 71 additions and 5 deletions

49
debug_events.py Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env python
"""
Location2025とイベントの関係を調査するスクリプト
"""
from rog.models import Location2025, NewEvent2
from django.db import connection
def main():
print('=== Location2025とイベントの関係調査 ===')
# Location2025のeventフィールドの外部キー先を確認
event_field = Location2025._meta.get_field('event')
print(f'Location2025.event field references: {event_field.related_model}')
# 現在のLocation2025データのイベント分布
print('\n=== Location2025のイベント分布 ===')
cursor = connection.cursor()
cursor.execute("""
SELECT l.event_id, ne.event_name, COUNT(*) as count
FROM rog_location2025 l
LEFT JOIN rog_newevent2 ne ON l.event_id = ne.id
GROUP BY l.event_id, ne.event_name
ORDER BY count DESC
""")
for row in cursor.fetchall():
event_id, event_name, count = row
print(f' Event ID {event_id}: {event_name} ({count}件)')
# NewEvent2の一覧
print('\n=== NewEvent2テーブルの全イベント ===')
for event in NewEvent2.objects.all()[:10]:
print(f' ID {event.id}: {event.event_name} (status: {event.status})')
# CSVアップロード画面のイベント選択肢を確認
print('\n=== CSVアップロード画面のイベント選択肢 ===')
events = NewEvent2.objects.filter(status='public').order_by('-start_datetime')
for event in events[:5]:
print(f' ID {event.id}: {event.event_name} (status: {event.status}, start: {event.start_datetime})')
# 実際のLocation2025サンプルデータ
print('\n=== Location2025サンプルデータ ===')
sample_locations = Location2025.objects.all()[:3]
for loc in sample_locations:
print(f' CP{loc.cp_number}: {loc.cp_name} -> Event ID {loc.event_id} ({loc.event.event_name if loc.event else "None"})')
if __name__ == '__main__':
main()

View File

@ -743,7 +743,7 @@ class LocationAdmin(LeafletGeoAdmin):
search_fields = ('location_id', 'cp', 'location_name', 'category', 'event_name','group',) search_fields = ('location_id', 'cp', 'location_name', 'category', 'event_name','group',)
list_filter = ('event_name', 'group',) list_filter = ('event_name', 'group',)
ordering = ('location_id', 'cp',) ordering = ('location_id', 'cp',)
list_display = ('location_id','sub_loc_id', 'cp', 'location_name', 'photos', 'category', 'group', 'event_name', 'event_active', 'auto_checkin', 'checkin_radius', 'checkin_point', 'buy_point',) list_display = ('location_id','sub_loc_id', 'cp', 'location_name', 'photos', 'category', 'group', 'event_name', 'auto_checkin', 'checkin_radius', 'checkin_point', 'buy_point',)
def tranfer_to_location(modeladmin, request, queryset): def tranfer_to_location(modeladmin, request, queryset):
@ -848,7 +848,7 @@ class TempLocationAdmin(LeafletGeoAdmin):
search_fields = ('location_id', 'cp', 'location_name', 'category', 'event_name',) search_fields = ('location_id', 'cp', 'location_name', 'category', 'event_name',)
list_filter = ('category', 'event_name',) list_filter = ('category', 'event_name',)
ordering = ('location_id', 'cp',) ordering = ('location_id', 'cp',)
list_display = ('location_id','cp', 'location_name', 'category', 'event_name', 'event_active', 'auto_checkin', 'checkin_radius', 'checkin_point', 'buy_point',) list_display = ('location_id','cp', 'location_name', 'category', 'event_name', 'auto_checkin', 'checkin_radius', 'checkin_point', 'buy_point',)
actions = [tranfer_to_location,] actions = [tranfer_to_location,]
@ -1158,7 +1158,10 @@ class Location2025Admin(LeafletGeoAdmin):
# フォーム表示 - Location2025システム用 # フォーム表示 - Location2025システム用
from .models import NewEvent2 from .models import NewEvent2
# statusフィールドベースでアクティブなイベントを取得 # スタッフユーザーの場合は全ステータスのイベントを表示
if request.user.is_staff:
events = NewEvent2.objects.all().order_by('-start_datetime')
else:
events = NewEvent2.objects.filter(status='public').order_by('-start_datetime') events = NewEvent2.objects.filter(status='public').order_by('-start_datetime')
return render(request, 'admin/location2025/upload_csv.html', { return render(request, 'admin/location2025/upload_csv.html', {

View File

@ -4,6 +4,20 @@
{% block content %} {% block content %}
<h1>チェックポイントCSVアップロード</h1> <h1>チェックポイントCSVアップロード</h1>
{% if user.is_staff %}
<div class="messagelist">
<div class="info">
<strong>スタッフユーザー:</strong> 全ステータスdraft, private, publicのイベントが表示されます。
</div>
</div>
{% else %}
<div class="messagelist">
<div class="info">
<strong>一般ユーザー:</strong> publicステータスのイベントのみが表示されます。
</div>
</div>
{% endif %}
<div class="module"> <div class="module">
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
@ -14,7 +28,7 @@
<select name="event" required> <select name="event" required>
<option value="">-- イベントを選択 --</option> <option value="">-- イベントを選択 --</option>
{% for event in events %} {% for event in events %}
<option value="{{ event.id }}">{{ event.event_name }}</option> <option value="{{ event.id }}">{{ event.event_name }} ({{ event.status }})</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>