# Django Event ID Routing and URL Handling ## How event_id is used in URLs and Routing - The system uses event-specific URLs for registration and attendance marking, such as: - `/attendance/register//` → Register for a specific event - `/attendance/mark//` → Mark attendance for a specific event - These routes are defined in `attendance/urls.py`: path('register//', views.register_user, name='register_user'), path('mark//', views.mark_attendance_for_event, name='mark_attendance_for_event'), - The `event_id` is passed as a parameter to the corresponding Django view function. ## How the logic works in Django views - In `register_user(request, event_id=None)`, the event is fetched using: event = get_object_or_404(Event, id=event_id) - The view checks if the event is upcoming and handles registration for that event only. - The user is registered for the event using a ManyToManyField (`user.events.add(event)`). - In `mark_attendance_for_event(request, event_id)`, the event is fetched similarly, and the page only allows marking attendance for that event if it is upcoming. - In `ajax_mark_attendance(request, event_id=None)`, the event is fetched and the logic ensures: - Only users registered for the event (user.events contains the event) can mark attendance for that event. - If not registered, a message is returned: "You are not registered for this event." ## Summary - The event_id in the URL ensures all registration and attendance actions are event-specific. - The backend logic enforces that only registered users can mark attendance for the correct event.