I've created a function that adds the user to an event, that is working fine but, i'm having problems with the one that removes the users from the event, I didn`t figure out how to get the attendant so that the owner can remove it.
By now, I have this:
views.py (Function that adds the user to the event)
@login_required
def request_event(request, pk):
previous = request.META.get('HTTP_REFERER')
try:
post = Post.objects.get(pk=pk)
Attending.objects.create(post=post, attendant=request.user)
messages.success(request, f'Request sent!')
return redirect(previous)
except post.DoesNotExist:
return redirect('/')
(Function that removes users from the event, handled by the event owner)
@login_required
def remove_attendant(request, pk, id):
previous = request.META.get('HTTP_REFERER')
try:
post = Post.objects.get(pk=pk)
attendant = Attending.objects.get(id=attendance_id)
Attending.objects.filter(post=post, attendant=attendant).delete()
messages.success(request, f'User removed!')
return redirect(previous)
except post.DoesNotExist:
return redirect('/')
Urls.py
path('post/(?P<pk>[0-9]+)/remove_attendant/(?P<attendance_id>[0-9]+)$', views.remove_attendant, name='remove-attendant'),
Any help or comment will be very welcome! thank you!!!