0

I have a custom user model that extends AbstractUser. When a new user is created, there are two other objects that I want created. Every user has an associated points model and cash model. These keep track of the points and cash they have, respectively. I want it so a points and cash model are created when a new user is created. How can I do this? Will my model code need to be provided, or is there general way of accomplishing this?

Iohannes
  • 267
  • 1
  • 4
  • 13
  • if you indeed need that behaviour, add a custom model manager that implement this – alko Nov 02 '13 at 17:30
  • OR you can use django signals to do a post_save_connect on the save of user, you can trigger the save and initialization of points and cash models. Why my answer was deleted for mentioning this idea I do not fully understand. If am totally wrong and there is a clear reason to use a manager vs. override save vs use a signal, I think the group could learn something from that discussion vs a deletion. Isn't that what downvotes are for? – mconlin Nov 02 '13 at 23:49
  • @mconlin Hm? I am new to StackOverflow so I dunno if you're saying that I deleted your comment or not. I'm not sure how comments are deleted to begin with. Anyway, I was expecting someone to mention signals (hoping for it, actually) since I don't understand it much and someone may be able to explain it in simpler terms to me. – Iohannes Nov 03 '13 at 00:55
  • @lohannes, you didn't do anything. A moderator deleted an answer I posted about signals. Signals are essentially a way for you to do some action, when some otheor action occurs. So you can cause Model B to save or update when Model A is done saving. Here is an example from another answer I found useful: http://stackoverflow.com/questions/1910359/creating-a-extended-user-profile/1911084#1911084 – mconlin Nov 03 '13 at 01:53

0 Answers0