diff options
Diffstat (limited to '97suifangqa/apps/profile/utils.py')
-rw-r--r-- | 97suifangqa/apps/profile/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/97suifangqa/apps/profile/utils.py b/97suifangqa/apps/profile/utils.py new file mode 100644 index 0000000..27067d5 --- /dev/null +++ b/97suifangqa/apps/profile/utils.py @@ -0,0 +1,19 @@ +#-*- coding: utf-8 -*- + +import random + +from django.conf import settings + + +def avatar_by_user(user): + """ + 生成头像 + """ + from django.core.files.images import ImageFile + + _avatar_path = "%s/avatars/%s.png" % (settings.MEDIA_ROOT, random.randint(1,22)) + + _avatar = ImageFile(open(_avatar_path)) + user.profile.avatar = _avatar + user.profile.save() + return user.profile
\ No newline at end of file |