I used to put custom user-related fields in a new UserProfile class, but now I saw in another project that it’s possible to use the contribute_to_class method of a model field to be able to append new fields to the auth.User model.
What are the advantages and downsides of each approach?
The biggest is probably that
contribute_to_classis undocumented, and the Django docs make it very clear that the approved methodology is using profiles to add additional data toUser. Python is a very powerful language and lets you do a number of “clever” things to accomplish some desired goal. But, convention is there to guide you away from the dark side.If there’s a solid, rational, necessary reason to use
contribute_to_classinstead of profiles, then perhaps it would be okay. I’m not entirely sure what such a reason would be, but maybe if you could prove some sort of performance improvement in that approach that was necessary for an app that needed to be highly performant.More likely than not, though, such cases will be few and far between if they exist at all. Barring all else, follow convention.