I want to make my User objects all have the same base behaviour and to do so I need to add a couple of methods / properties to Anonymous User.
I’ve already subclassed User to make richer user objects but I was wondering if anyone has done the same for Anonymous User? And if there are any preferred ways of doing it!
Your middleware suggestion got me thinking, and I now think the best idea is to overwrite the standard
AuthenticationMiddleware. That class assigns aLazyUserobject to the request, which is resolved to the correct user, when accessed, by callingcontrib.auth.get_user. This is probably the right place to override things, so that it calls your customisedget_userfunction which returns your subclassedAnonymousUser.