The point is that to get the partition function you have to sum over all states, with the usual Boltzmann weight factor $e^{-\beta E}$.
If you label the energy eigenstates of your system with $| n \rangle$ then the partition function will have the form $$ \tag{1} Z = \sum_n g_n e^{-\beta E_n},$$ where $E_n$ is the energy of the $n$-th state, and $g_n$ is a possibly present degeneracy factor counting the number of states with energy $E_n$ (which in the non-degenerate case is equal to 1 and thus unnecessary).
If you are dealing with a many-particles system one way to label the states is by specifying the configuration $\{ n_j\}_j$, i.e. the occupation number $n_j$ of the $j$-th particle, for every particle $j=1,...,N$, and the partition function can accordingly be written as $$ \tag{2} Z= \sum_{\{n_j\}} g(\{n_j\}) e^{-\beta E(\{n_j\})}, $$ where it is important to notice that the energy $E$ depends on the configuration $\{n_j\}$.
However, while (2) is usually more practical in these circumstances, one could equally well express the partition function in the form (1). To try to make it clearer I'll show how we would do this: let $E_j$ denote the eigenenergies of the total system (so rembember that this $j$ is different from the one used above, which labeled one-particle states). Then the partition function has the form $$ \tag{3} Z = \sum_j g_j e^{-\beta E_j}.$$ Why is this equal to (2)? Because we are still counting all states, just in a different way. Now $g_j$ is the number of states with total energy $E_j$, i.e. in terms of how the single-particle states are distributed: $$ g_j = \sum_{\{n_{\textbf p} \}\, | \sum_{\textbf p} \!\epsilon_{\textbf p}=E_j} g( \{n_{\textbf p} \}),$$ where $\epsilon_{\textbf p}$ is the energy of an electron in the state $\textbf p$, and I am now labeling single particle states using their momenta $\textbf p$.