What is the best place to insert data, for example a foreign key (site_id)?
I have tried both (on the view):
def form_valid(self, form):
site_id = self.kwargs['site_id']
self.object = form.save(commit=False)
self.object.site_id = self.kwargs['site_id']
self.object.save()
return HttpResponseRedirect(self.get_success_url())
and:
def post(self, request, *args, **kwargs ):
self.object.site_id = self.kwargs['site_id']
return super().post(request, *args, **kwargs)
both seem to work, but is one better, more ‘correct’, if so why?
Also, since I am overriding these functions is here any need to call the corresponding ‘super().init’?
thanks