From 9303415b89267ad416ec0950e551f33f8b3621aa Mon Sep 17 00:00:00 2001 From: ibuler Date: Sun, 14 Aug 2016 00:40:21 +0800 Subject: [PATCH] modify some issues --- apps/users/migrations/0001_initial.py | 40 ++++++++++++++++--- .../migrations/0002_auto_20160810_1516.py | 23 ----------- apps/users/models.py | 36 +++++++++++++++-- docs/table_design.xml | 25 ++++++++---- requirements.txt | 0 5 files changed, 85 insertions(+), 39 deletions(-) delete mode 100644 apps/users/migrations/0002_auto_20160810_1516.py create mode 100644 requirements.txt diff --git a/apps/users/migrations/0001_initial.py b/apps/users/migrations/0001_initial.py index 1f7be6ac9..b399a3d5e 100644 --- a/apps/users/migrations/0001_initial.py +++ b/apps/users/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-08-09 17:23 +# Generated by Django 1.10 on 2016-08-13 16:36 from __future__ import unicode_literals import django.contrib.auth.models @@ -32,28 +32,56 @@ class Migration(migrations.Migration): ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('avatar', models.ImageField(default='', upload_to=b'', verbose_name='\u5934\u50cf')), + ('wechat', models.CharField(max_length=30, verbose_name='\u5fae\u4fe1')), + ('phone', models.CharField(max_length=20, verbose_name='\u624b\u673a')), + ('enable_2FA', models.BooleanField(default=False, verbose_name='\u542f\u7528\u4e8c\u6b21\u9a8c\u8bc1')), + ('secret_key_2FA', models.CharField(max_length=16)), + ('private_key', models.CharField(max_length=5000)), + ('public_key', models.CharField(max_length=1000)), + ('created_by', models.CharField(max_length=30)), + ('date_expired', models.DateTimeField()), ], options={ - 'abstract': False, - 'verbose_name': 'user', - 'verbose_name_plural': 'users', + 'db_table': 'user', }, managers=[ ('objects', django.contrib.auth.models.UserManager()), ], ), migrations.CreateModel( - name='Group', + name='Role', fields=[ ('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.Group')), ('comment', models.CharField(blank=True, max_length=80)), ], + options={ + 'db_table': 'role', + }, bases=('auth.group',), ), + migrations.CreateModel( + name='UserGroup', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(help_text='\u8bf7\u8f93\u5165\u7ec4\u540d\u79f0', max_length=100, unique=True, verbose_name='\u7ec4\u540d\u79f0')), + ('comment', models.TextField(blank=True, help_text='\u8bf7\u8f93\u5165\u7528\u6237\u7ec4\u63cf\u8ff0', verbose_name='\u63cf\u8ff0')), + ('date_added', models.DateTimeField(auto_now_add=True)), + ('created_by', models.CharField(max_length=100)), + ], + options={ + 'db_table': 'usergroup', + }, + ), migrations.AddField( model_name='user', name='groups', - field=models.ManyToManyField(to='users.Group'), + field=models.ManyToManyField(to='users.UserGroup'), + ), + migrations.AddField( + model_name='user', + name='role', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='users.Role'), ), migrations.AddField( model_name='user', diff --git a/apps/users/migrations/0002_auto_20160810_1516.py b/apps/users/migrations/0002_auto_20160810_1516.py deleted file mode 100644 index 43a37c0f6..000000000 --- a/apps/users/migrations/0002_auto_20160810_1516.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10 on 2016-08-10 07:16 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('users', '0001_initial'), - ] - - operations = [ - migrations.AlterModelOptions( - name='user', - options={}, - ), - migrations.AlterModelTable( - name='user', - table='user', - ), - ] diff --git a/apps/users/models.py b/apps/users/models.py index cbbdec411..410608454 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -1,3 +1,5 @@ +# ~*~ coding: utf-8 ~*~ + from __future__ import unicode_literals from django.db import models @@ -5,13 +7,41 @@ from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import Group as AbstractGroup -class Group(AbstractGroup): +class Role(AbstractGroup): comment = models.CharField(max_length=80, blank=True) + def __unicode__(self): + return self.name + + class Meta: + db_table = 'role' + + +class UserGroup(models.Model): + name = models.CharField(max_length=100, unique=True, verbose_name='组名称', help_text='请输入组名称') + comment = models.TextField(blank=True, verbose_name='描述', help_text='请输入用户组描述') + date_added = models.DateTimeField(auto_now_add=True) + created_by = models.CharField(max_length=100) + + def __unicode__(self): + return self.name + + class Meta: + db_table = 'usergroup' + class User(AbstractUser): - - groups = models.ManyToManyField(Group) + groups = models.ManyToManyField(UserGroup) + avatar = models.ImageField(verbose_name='头像', default='') + wechat = models.CharField(max_length=30, verbose_name='微信') + phone = models.CharField(max_length=20, verbose_name='手机') + enable_2FA = models.BooleanField(default=False, verbose_name='启用二次验证') + secret_key_2FA = models.CharField(max_length=16) + role = models.ForeignKey(Role, on_delete=models.PROTECT) + private_key = models.CharField(max_length=5000) # ssh key max length 4096 bit + public_key = models.CharField(max_length=1000) + created_by = models.CharField(max_length=30) + date_expired = models.DateTimeField() @property def name(self): diff --git a/docs/table_design.xml b/docs/table_design.xml index 066f1534c..78c6ea405 100644 --- a/docs/table_design.xml +++ b/docs/table_design.xml @@ -1,6 +1,6 @@ - + @@ -127,6 +127,9 @@ DATETIME NULL + +VARCHAR +NULL id @@ -229,7 +232,7 @@ NULL INTEGER -NULL +NULL VARCHAR @@ -251,7 +254,7 @@ NULL INTEGER -NULL +NULL VARCHAR @@ -276,7 +279,7 @@ id - +
INTEGER NULL @@ -318,6 +321,9 @@ VARCHAR NULL + +VARCHAR +NULL DATETIME NULL @@ -325,7 +331,7 @@ id
- +
INTEGER NULL @@ -335,8 +341,7 @@ VARCHAR -NULL - +NULL VARCHAR NULL @@ -544,6 +549,12 @@ CHAR NULL + +VARCHAR +NULL + +TIME +NULL id diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..e69de29bb