Update data inside class based detail view
What you here describe is in essence an UpdateView
[Django-doc]. I would suggest that you use this with:
from django.urls import reverse_lazy
class GeographyDetailView(LoginRequiredMixin, UpdateView):
model = Geography
form_class = GeographyForm
success_url = reverse_lazy('geography')
template_name = 'some_template.html'
def get_queryset(self):
return super().get_queryset().filter(
student=self.request.user
)
This should be sufficient: it will pass the object to edit as object
to the context, and the form as form
to the rendering context.
The form should be submitted to the same view as this one and will redirect to the geography
view in case the form is valid.
The get_queryset
filters on the student
. This means that it will return a HTTP 404 response in case the user that aims to edit the object is not the student
of that object.