django: create user profile for existing users automatically

前端 未结 3 1351
终归单人心
终归单人心 2021-01-03 18:47

I added a new UserProfile Model to my project today.

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    ...

    def __unicode__(self         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-03 19:30

    In response to your code I'll say to put a get_or_create also in a post_init listener for User.

    If this "all fields null is ok" profile is just a fast example I'd put a middleware redirecting all users with no profile to the settings page asking them to fill additional data. ( probably you want to do this anyway, no one in the real world will add new data to their existing profiles if not forced or gamified into it :) )

提交回复
热议问题