The best place to insert data

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

To a degree it depends upon which views you’re overriding here. For example, if this were a CreateView, your overridden post method would not work as written.

Personally, I tend to prefer the form_valid method. No specific technical reason, more a choice of style.

I don’t think I’ve ever overridden __init__ of a Class-Based View. I’ve never seen the need. (I’m even having a difficult time thinking of a reason why I’d ever want to.)

Thank you, thats very helpful