You can buy a house at any time if you have a Nanjing household registration. If you don't have a Nanjing household registration, you need to pay social security or individual tax for more than 2 years, or you can buy a house with a senior professional title or master's degree or above.
Nanjing collective hukou can also buy a house, so it is also possible to buy a house by transferring the hukou to a school collective household. Policies in different regions may be different.