UserProfile documentation (not extensive enough)
|Reported by:||foxwhisper||Owned by:||melinath|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The method get_profile() does not create the profile, if it does not exist. You need to register a handler for the signal django.db.models.signals.post_save on the User model, and, in the handler, if created=True, create the associated user profile.
However, it does not show how to do this. For new users, this will be quite off putting, especially as most people skim the documentation, and don't bother with the 'fat'.
May I suggest the documentation is included to use the following snippet:
#in models.py from django.contrib.auth.models import User from django.db.models.signals import post_save class UserProfile(models.Model): user = models.OneToOneField(User) #other fields here def __str__(self): return "%s's profile" % self.user def create_user_profile(sender, instance, created, **kwargs): if created: profile, created = UserProfile.objects.get_or_create(user=instance) post_save.connect(create_user_profile, sender=User) #in settings.py AUTH_PROFILE_MODULE = 'YOURAPP.UserProfile'
Change History (13)
comment:1 follow-up: ↓ 5 Changed 5 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
comment:2 Changed 5 years ago by melinath
- Owner changed from nobody to melinath
- Status changed from new to assigned