Just learning Django and have come up against a blocker I’m having trouble resolving.
I am creating an app where you can add a ‘trip’, and to these trips you can add a ‘note’
I have managed to get adding,updating and deleting of trips working , but I cannot get the deletion of notes to work correctly, specifically if i want to cancel the deletion on the note_confirm_delete template.
This is my DeleteView
class NoteDeleteView(LoginRequiredMixin, DeleteView):
model = Note
pk_url_kwarg = 'note_pk'
def get_success_url(self, **kwargs):
success_url = f'/trips/{str(self.kwargs["trip_pk"])}'
return success_url
and this is the href link in my template
<a href="{% url 'trips:trip-detail' object.id %}"
now the object.id is the id of the note but i need to get the pk of the related trip as on deletion I want to go back to trips/int:pk
How can i do this, I’ve messed around with context etc but getting a bit tied up in knots, can anyone push me in right direction to help me solve please?
Relevant URLs paths are below:
path('trips/<int:pk>/', TripDetailView.as_view(), name='trip-detail'),
# Page to add new trips
path('trips/new/', TripCreateView.as_view(), name='trip-create'),
# Path to update trip
path('trips/<int:pk>/update/', TripUpdateView.as_view(), name='trip-update'),
# Path to delete trip
path('trips/<int:pk>/delete/', TripDeleteView.as_view(), name='trip-delete'),
# Path to add new note
path('trips/<int:pk>/note/new/', NoteCreateView.as_view(), name='note-create'),
# Path to update note
path('trips/<int:trip_pk>/note/<int:note_pk>/update/', NoteUpdateView.as_view(), name='note-update'),
# Path to delete note
path('trips/<int:trip_pk>/note/<int:note_pk>/delete/', NoteDeleteView.as_view(), name='note-delete'),
I have another query re the way I have constructed the note url paths, as in is this best way to do it? But i will ask another question, however unsure if its related to my issue in this question
Thanks in advance