Fix inbound2 issue
This commit is contained in:
24
rog/views.py
24
rog/views.py
@ -569,19 +569,29 @@ def LocationInBound2(request):
|
||||
|
||||
if lat is not None and lon is not None:
|
||||
if grp:
|
||||
# grpがある場合、最初に絞り込む
|
||||
base_query = Location2025.objects.filter(group__contains=grp)
|
||||
# grpがある場合、イベント名に基づいてフィルタリング
|
||||
from rog.models import NewEvent2
|
||||
from django.db.models import Q
|
||||
|
||||
# grpパラメータでイベントを検索
|
||||
events = NewEvent2.objects.filter(
|
||||
Q(event_code=grp) |
|
||||
Q(event_name__icontains=grp)
|
||||
)
|
||||
|
||||
if events.exists():
|
||||
base_query = Location2025.objects.filter(event__in=events)
|
||||
else:
|
||||
# イベントが見つからない場合は空のクエリセット
|
||||
base_query = Location2025.objects.none()
|
||||
else:
|
||||
current_point = Point(lon, lat, srid=4326)
|
||||
# 10km四方の領域を指定
|
||||
distance_from_point = 40000 # 中心から10km(半径)
|
||||
|
||||
base_query = Location2025.objects.filter(
|
||||
geom__distance_lte=(current_point, D(m=distance_from_point))
|
||||
).annotate(distance=Distance('geom', current_point)).order_by('distance')
|
||||
|
||||
if grp:
|
||||
base_query = base_query.filter(group__contains=grp)
|
||||
location__distance_lte=(current_point, D(m=distance_from_point))
|
||||
).annotate(distance=Distance('location', current_point)).order_by('distance')
|
||||
|
||||
logger.debug(f"Final query: {base_query.query}")
|
||||
locs = base_query
|
||||
|
||||
Reference in New Issue
Block a user