How to second-quantize an operator if the field operator is a spinor In non-relativistic QM, one normally second-quantizes an operator using
$$ \hat O=\int d^3r~\hat\psi^\dagger(r)O~\hat\psi(r),\qquad(1)$$
where the field operator $\hat\psi$ is given by
$$\hat\psi(r)=\sum_{n\in\{\mathrm{states}\}}\hat a_n\psi_n(r),\qquad(2)$$
with $\hat a_n$ the annihilation operator of a particle with state $\psi_n$ (and the latter is further assumed to be normalized to 1).
How would one proceed if the particles in question are, for example, electrons? In that case the field operator should be modified to be a spinor, and its expression would be instead
$$\hat\psi(r)=\sum_{n, \sigma}\hat a_{n,\sigma}\psi_n(r)\chi_\sigma, \qquad(3)$$
where $\chi_\sigma$ is the spinor corresponding to an electron of spin $\sigma$ along the quantization axis. How would one give an analogous expression to eq. (1) in this case? If $O$ is a scalar then $\hat O$ should be too, because otherwise we could change the tensor character of the operators just by choosing a different basis with respect to which we are quantizing them. This makes me think that the appropriate way to express $\hat O$ in this basis should be something like
$$ \hat O=\sum_{\sigma}\int d^3r~\hat\psi^\dagger_\sigma(r)O~\hat\psi_{\sigma}(r)\qquad(4)$$
where $\psi_{\sigma}(r)$ represents the $\sigma$th spinorial component of $\hat\psi(r)$ as given in eq. (3). It seems rather logical to extend eq. (1) to eq. (4), because in essence both formulas are just giving a kind of "trace" of $O$ with respect to the internal degrees of freedom of $\hat\psi(r)$, the only difference being that in eq. (1) the only internal degree of freedom is the position, whereas in eq. (4) the field operator also has spin degrees of freedom.
Is this correct? Or is the correct second-quantization of this quantities performed in a different way?
 A: Let $\mathfrak h $ be the $1$-particle Hilbert space. Let $\mathcal O$ be an operator on $\mathfrak h$. The second-quantized version of this operator acts on an $k$-particle state $S_\nu(\phi_1\otimes\ldots\otimes \phi_k)$  (where $S_{\nu}$ is the (anti-) symmetrization appropriate for the particles at hand) as :
$$\hat{\mathcal O}S_\nu(\phi_1\otimes\ldots\otimes \phi_k) = \sum_{i=1}^k S_\nu (\phi_1\otimes\ldots\otimes (O\phi_i)\otimes\ldots\otimes \phi_k)$$
If $\{|\alpha\rangle\}$ are a basis of $\mathfrak h$, we have :
$$\hat{\mathcal O} = \sum_{\alpha,\beta} \hat a^\dagger_\beta \langle \beta|\mathcal O|\alpha\rangle \hat a_\alpha$$
To see what happens with internal degrees of freedom, let $\mathfrak h = L^2(\mathbb R^d)\otimes \mathfrak h_{\rm{int}}$
and take $\{\psi_n\}$ be a basis of $L^2(\mathbb R^d)$ and $\{\chi_\sigma\}$ a basis of $\mathfrak h_{\rm{int}}$. With the previous notations, we have  $\alpha= (n,\sigma)$ and $|n,\sigma \rangle = \psi_n\otimes \chi_\sigma$.
A scalar operator $\mathcal O$ is one which acts only on the $L^2(\mathbb R^d)$ factor, ie :
$$\langle n,\sigma |\mathcal O|m,\sigma'\rangle = \langle n|\mathcal O|m\rangle \delta_{\sigma,\sigma'} = \delta_{\sigma,\sigma'}\int \text d r \psi_n^*(r)\mathcal O\psi_m(r)$$
For such an operator, the second-quantized version reads :
\begin{align}
\hat {\mathcal O}&=\sum_{n,m,\sigma} \hat a_{n,\sigma}^\dagger\langle n|\mathcal O|m\rangle \hat a_{m,\sigma}\\
&= \sum_{\sigma}\int \text dr \hat\psi^\dagger_\sigma(r) \mathcal O\hat \psi_\sigma(r)
\end{align}
where we used $\hat \psi_\sigma(r) = \sum_n \hat a_{n,\sigma} \psi_n(r)$. This matches the result in OP. This derivation can also be generalized to operators acting on the spin degrees of freedom.
