This is very basic, but I can't find anything on it. I have a user profile defined in the following way:
def create_user_info(sender, instance, created, **kwargs):
if created:
UserInfo.objects.create(user=instance)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
Now how do I set the properties?
First off. Monkey-patching User
is not the correct approach. Set AUTH_PROFILE_MODULE = 'yourapp.UserInfo'
in settings.py, and then you can use user_instance.get_profile()
automatically to get the profile.
So, then to modify the profile you just do:
profile = user.get_profile()
profile.some_field = 'some value'
profile.save()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.