This feels a lot like a problem sessions are going to solve for you. The main problem here is you are trying to save some information against the AnonymousUser which is a common object for all users that are not authenticated. The way I would approach this is to use database backed sessions saving the information (cart contents) there and then retrieving this and saving against the User/Customer model.
https://docs.djangoproject.com/en/5.2/topics/http/sessions/
As an aside what's the difference between a User
and a Customer
? It could be argued they are the same thing except a customer has a sales history (which could be a seperate Sale
model)