From bcae7beae63f19cd33548b0dedd7a4b364d53801 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 17 Aug 2016 00:36:54 +0800 Subject: [PATCH] upload avatar --- apps/jumpserver/settings.py | 1 + apps/users/forms.py | 2 +- .../migrations/0006_merge_20160817_0032.py | 16 +++++++++++++++ .../migrations/0007_auto_20160817_0032.py | 20 +++++++++++++++++++ apps/users/models.py | 2 +- apps/users/templates/users/_user.html | 1 + 6 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 apps/users/migrations/0006_merge_20160817_0032.py create mode 100644 apps/users/migrations/0007_auto_20160817_0032.py diff --git a/apps/jumpserver/settings.py b/apps/jumpserver/settings.py index 0399343c6..069bd52bf 100644 --- a/apps/jumpserver/settings.py +++ b/apps/jumpserver/settings.py @@ -131,3 +131,4 @@ STATICFILES_DIRS = ( AUTH_USER_MODEL = 'users.User' BOOTSTRAP_COLUMN_COUNT = 11 +MEDIA_ROOT = os.path.join(BASE_DIR, 'img').replace('\\', '/') + '/' diff --git a/apps/users/forms.py b/apps/users/forms.py index b57b516ba..9974c47ae 100644 --- a/apps/users/forms.py +++ b/apps/users/forms.py @@ -10,7 +10,7 @@ class UserForm(ModelForm): class Meta: model = User fields = [ - 'username', 'name', 'email', 'groups', 'wechat', + 'username', 'name', 'email', 'groups', 'wechat', 'avatar', 'phone', 'enable_2FA', 'role', 'date_expired', 'comment', ] # widgets = { diff --git a/apps/users/migrations/0006_merge_20160817_0032.py b/apps/users/migrations/0006_merge_20160817_0032.py new file mode 100644 index 000000000..594dbefc0 --- /dev/null +++ b/apps/users/migrations/0006_merge_20160817_0032.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-08-16 16:32 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0005_auto_20160816_1358'), + ('users', '0005_auto_20160816_2252'), + ] + + operations = [ + ] diff --git a/apps/users/migrations/0007_auto_20160817_0032.py b/apps/users/migrations/0007_auto_20160817_0032.py new file mode 100644 index 000000000..aa5eb3341 --- /dev/null +++ b/apps/users/migrations/0007_auto_20160817_0032.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-08-16 16:32 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0006_merge_20160817_0032'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='avatar', + field=models.ImageField(blank=True, upload_to='avatar', verbose_name='\u5934\u50cf'), + ), + ] diff --git a/apps/users/models.py b/apps/users/models.py index d77c3a8f1..1769fb208 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -61,7 +61,7 @@ class User(AbstractUser): name = models.CharField(max_length=20, verbose_name='姓名', help_text='* required') email = models.EmailField(max_length=30, unique=True, verbose_name='邮件', help_text='* required') groups = models.ManyToManyField(UserGroup, verbose_name='用户组') - avatar = models.ImageField(verbose_name='头像', blank=True) + avatar = models.ImageField(upload_to="avatar", verbose_name='头像', blank=True) wechat = models.CharField(max_length=30, blank=True, verbose_name='微信') phone = models.CharField(max_length=20, blank=True, verbose_name='手机号') enable_2FA = models.BooleanField(default=False, verbose_name='启用二次验证') diff --git a/apps/users/templates/users/_user.html b/apps/users/templates/users/_user.html index 3c6e08eac..c2d3d742e 100644 --- a/apps/users/templates/users/_user.html +++ b/apps/users/templates/users/_user.html @@ -49,6 +49,7 @@

信息

+ {{ form.avatar|bootstrap_horizontal }} {{ form.phone|bootstrap_horizontal }} {{ form.wechat|bootstrap_horizontal }} {{ form.comment|bootstrap_horizontal }}